Profile Picture

Open positions terminating incorrectly -- RE system evaluation

Posted By tdonnelly 3 Years Ago

Open positions terminating incorrectly -- RE system evaluation

Message
Posted Monday May 12 2014
Hi everyone,

I'm evaluating RE, after having taken a good look at Wealth Lab over the past couple of weeks. I can easily see the power and flexibility of RE, as well as the more logical way it processes trade instructions. However, my C# coding skills are sadly still in their infancy, so I'm using drag and drop as my primary evaluation method (which I realize misses the power of RE's coding flexibility).

One immediate problem has surfaced, and I'm hoping someone out there can help. I designed a simple testing system, using a generic Turtle-like breakout with no trend filters. (I'm comparing the results for this system to WL, as well as to an Excel mock-up).

The system rules create a buy open order when the current closing price is greater than the highest close over the past 50 bars (yes, I'm using the Shift Series indicator for the lookback part). The open buy order is terminated when the current closing price is less than (falls below) the lowest close for the previous 25 bars.

Short orders use the same structure: a short order is opened if the current closing price is less than the lowest close for the past 50 bars; and covered when the current closing price is greater than the highest close over the past 25 bars.

Here's the problem: using RE's DaD UI, I created four separate triggers based on Comparison indicators - one for each Buy Open and Short Open trigger, and one for each Buy Close and Short Cover trigger.

But when I run the system, I realize -- particularly when compared to my Excel mock-up -- that open Buy positions are being incorrectly closed by my Short Cover trigger; and my open Short positions are being closed (covered) by my Buy Close trigger!

In WL, this was essentially impossible because you typically link each position opening trigger to a matching position closing trigger; but in RE, this does not seem possible. I've looked through the RE User Guide, and also consulted the various indicators in the program itself, but a solution doesn't immediately jump out at me. How would I -- using the DaD UI - prevent position closing triggers from one side of a trade from prematurely shutting down open positions from the other side of the trade?

Many thanks for any help or advice.
Posted Tuesday May 13 2014
Hi tdonnelly,

It's not possible to associate a position close with a given position entry in RightEdge's drag and drop.  You will have to use some code for this.

To do so, just remove the "Close Position" actions from your system, but leave all 4 triggers there as well as the position entry actions.  Rename your position exit triggers to "CloseLong" and "CloseShort" (which you can do by double-clicking the name in the system designer).

Then, use the following code for your Symbol Script's NewBar method:

       public override void NewBar()

       {

              // Put your trading code here

             

              if (OpenPositions.Count > 0)

              {

                     Position pos = OpenPositions[0];

                    

                     ITrigger closeLongTrigger = SystemData.Triggers["CloseLong"][Symbol];

                     ITrigger closeShortTrigger = SystemData.Triggers["CloseShort"][Symbol];

             

                     if (pos.Type == PositionType.Long && closeLongTrigger.IsTriggered)

                     {

                           pos.CloseAtMarket("Exit long");

                     }

                     else if (pos.Type == PositionType.Short && closeShortTrigger.IsTriggered)

                     {

                           pos.CloseAtMarket("Exit short");

                     }                   

              }

       }

This code checks to see if any position is open, and then if it does it will close a long position if the CloseLong Drag and Drop trigger is triggered, and it will close a short position if the CloseShort Drag and Drop trigger is triggered.

Thanks,
Daniel

Posted Tuesday May 13 2014
Brilliant, Daniel. That worked beautifully! Many thanks - once I get this evaluation done, I'm definitely going to get going on enhancing my C# coding skills :->.


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems