I've tagged the entry with a signal name 'b1'.
Exits are tagged: 't1', 't2', 't3'
I created boolean vars associated with each exit, each turned off (set to false):
T1_xit
T2_xit
T3_xit
After each exit, I turn the associated var on (set to true).
I coded the Set logic to not execute the actions for the exit if it's associated boolean var is true.
PROBLEM: Though the exits are executing, I'm sometimes getting multiple t1 exits, even though the 1st exit should have set T1_xit to true. (I assume when the condition is true twice before the position is completely exited).
If you can find any logic error in my code, I'd appreciate it.
I've included the relevant info in the code snippet below (minus the actual condition logic).
protected override void OnStateChange() { if (State == State.SetDefaults) { Calculate = Calculate.OnPriceChange; EntriesPerDirection = 1; EntryHandling = EntryHandling.UniqueEntries; ... StopLoss = 1; T1_xit = false; T2_xit = false; T3_xit = false; } else if (State == State.DataLoaded) { ... SetStopLoss(@"b1", CalculationMode.Currency, StopLoss, false); } } protected override void OnBarUpdate() { // Set 1 // ENTRY, full position if ( <set 1 condition> ) { EnterLong(Convert.ToInt32(300), @"b1"); T1_xit = false; T2_xit = false; T3_xit = false; } // Set 2 // T1 Exit, 1/3 position if ( <set 2 condition> ) && (T1_xit == false) && (T2_xit == false) && (T3_xit == false)) { ExitLong(Convert.ToInt32(100), @"t1", @"b1"); T1_xit = true; } // Set 3 // T2 Exit, 1/3 position if ( <set 3 condition> ) && (T2_xit == false) && (T1_xit == true) && (T3_xit == false)) { ExitLong(Convert.ToInt32(100), @"t2", @"b1"); T2_xit = true; } // Set 4 // T3 Exit, 1/3 position if ( <set 4 condition> ) && (T3_xit == false) && (T1_xit == true) && (T2_xit == true)) { ExitLong(Convert.ToInt32(100), @"t3", @"b1"); T3_xit = true; } }
Comment