In the strategy I am working on there is going to be a situation whereby the code will be looking multiple entries and managing the STOPLOSS levels.
This is a brief explanation of what the code will be facing under live conditions.
First, the code will open a stop order with stoploss and takeprofit targets.
Then there will be conditions when after the stop order is filled that a new signal will appear.
The code will then need to do the following:
1. create a new stop order (with targets) from new signal
2. if there is an existing opened position the code needs to examine the stoploss target and see where it falls when compared to the new stop order LEVEL, ie we want the position to always close before the new stop level is filled..
In order to test this condition I need to have an open position with its own stop/limit targets and also a stop market order with its own stop/limit targets.
I am trying to simulate the simple scenario, I created a strategy that is supposed to do jus that open a position and a stop market order.
So far I am not able to open the stop market order.
Are there any examples out there that can provide this type of position/order setup?
Here is a simple snippet of the way I am attempting to simulate an open position and a new stop market order. Please advice.
Jess
if (State == State.SetDefaults) { Blah... blah Calculate = Calculate.OnBarClose; EntriesPerDirection = 2; blah .. blah } .... protected override void OnBarUpdate() { if(State == State.Historical) return; if (Bars.IsFirstBarOfSession && IsFirstTickOfBar) doneForSession = false; if (doneForSession) return; //Enter a long position if(Close[1]<Open[1] && Position.Quantity == 0) {[INDENT]EnterLong(1, "s"+Time[0]); //OPEN POSITION SetStopLoss("s"+Time[0], CalculationMode.Ticks, 20,false); //SET STOPLOSS 20 ticks away SetProfitTarget("s"+Time[0], CalculationMode.Ticks, 20); //SET TAKE PROFIT 20 ticks away[/INDENT] } //if we have 1 position open, create a long stop market order if (Position.Quantity == 1) {[INDENT]EnterLongStopMarket(0,true,1,High[1]+5*TickSize,"s2"+Time[0]); //OPEN STOP MARLET ORDER SetStopLoss("s2"+Time[0], CalculationMode.Ticks, 20,false); //SET STOPLOSS 20 ticks away(when filled) SetProfitTarget("s2"+Time[0], CalculationMode.Ticks, 20); //SET TAKE PROFIT 20 ticks away(when filled) } doneForSession=true;[/INDENT] } }
Comment