I am in the final stage of testing my automated strategy. In total I have 10 different sets of parameters and they all open (scalping) positions from time to time. For now, I allow each set two make two entries, but this number will go up in the future. Depending on the market it is thus possible that a set of entry parameters opens 2 short positions on 2 consecutive (renko) bars. (Or later 5, or 10 even)
Since both these positions are opened with the same parameters, they have the same amount of ticks for SL/BE and trailing stops.
And then the problems started :
The first and second 'SRA'-position did not only take the same amount of ticks as stoploss, but also the same Price level (they both had the name 'SRA', hence why) .
That is not behaviour that I am looking for. The wise and friendly forum user koganam put me on the right track and I started using IOrder to give every order 'born' from the same set of parameters a different name, like so:
// Condition set 1: Short Red Arrow if ([I]//my entry conditions are here[/I] ) { if (entryOrder1 == null) {entryOrder1 = EnterShort(1,DefaultQuantity, [COLOR=Red]"SRA1"[/COLOR]); OpSRA = Open[0]; Print(Time[0].ToString("dd/MM/yyyy") + ", " + Time[0].ToString("HH:mm:ss")+ " Short Red Arrow 1 @ " + Close[0]); DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[0] + 65 * TickSize, Color.Red); trailSRA = true;} else if (entryOrder2 == null) {entryOrder2 = EnterShort(1,DefaultQuantity, [COLOR=Red]"SRA2"[/COLOR]); OpSRA = Open[0]; Print(Time[0].ToString("dd/MM/yyyy") + ", " + Time[0].ToString("HH:mm:ss")+ " Short Red Arrow 2 @ " + Close[0]); DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[0] + 65 * TickSize, Color.Red); trailSRA = true;} }
//********* 1. SRA //Initial Stop on Open for SRA if (trailSRA == true && Position.MarketPosition == MarketPosition.Short && !initialSetSRA) { SetStopLoss("[COLOR=Red]SRA[/COLOR]",CalculationMode.Ticks,195,false); initialSetSRA = true; // set initial stop only once Print(Time[0].ToString("dd/MM/yyyy") + ", " + Time[0].ToString("HH:mm:ss") + " Open SL SRA set @ " + (Open[0] + (195 * TickSize))); } // Breakeven for SRA if (initialSetSRA && !BESetSRA && trailSRA == true && Position.MarketPosition == MarketPosition.Short && Close[0] <= Position.AvgPrice - 195 * TickSize) { SetStopLoss("[COLOR=Red]SRA[/COLOR]",CalculationMode.Price, Close[0] + 195 * TickSize, false); BESetSRA = true; // set BE stop once SRATrail = Close[0]; Print(Time[0].ToString("dd/MM/yyyy") + ", " + Time[0].ToString("HH:mm:ss") + " BE SRA set @ " + (Close[0] + 195 * TickSize)); } //Trailing Stop during for SRA if (BESetSRA && trailSRA == true && Position.MarketPosition == MarketPosition.Short && Close [0] < Close [1]) { SetStopLoss("[COLOR=Red]SRA[/COLOR]",CalculationMode.Price ,Close[0]+(65*TickSize),false); Print(Time[0].ToString("dd/MM/yyyy") + ", " + Time[0].ToString("HH:mm:ss") + " Trail SRA adjusted to " + (Close[0]+(65*TickSize))); }
Here's my question:
Do I really have to copy this set of SL/BE/Trail-parameters 10 times and rename them to SRA1, SRA2, SRA3,... SRA10 to allow 10 different entries to be handled correctly when it comes to SL/BE/Trail or can this be accomplished in a different way (perhaps with a for... loop ?? Or an array ??)
Having 10 sets of entry parameters and 10 different blocks of code per set for SL/BE/Trail seems overkill I did browse this forum (and others) for quite some time already, but no luck so far.
Bonus question: Can I further limit the amount of code so that the names of the different IOrders are given 'automatically' instead of having this line 10 times per entry set ??
else if (entryOrder2 == null) {entryOrder2 = EnterShort(1,DefaultQuantity, [COLOR=Red]"SRA2"[/COLOR]);
Thanks in advance !
Comment