1. If the current close price is lower than the current lowest value, set the new lowest value to the close price.
2. If the current close price is 100 ticks higher than the lowest value, enter a long order with a StopLoss and ProfitTarget.
3. If the SL or PT is hit, reset the lowest value.
Below is the code snippet:
public class myStrategy : Stragety { private double Lowest=double.MaxValue; private inOrder=false; //Blah blah blah... } protected override void OnBarUpdate() { if(!inOrder) { if(Close[0]<Lowest) Lowest=Close[0]; else if(Close[0]-Lowest>100*TickSize) { SetProfitTarget("Long1",CalculationMode.Price, Close[0]+10*TickSize); SetStopLoss("Long1",CalculationMode.Price, Close[0]-10*TickSize,false); EnterLong(Convert.ToInt32(DefaultQuantity), "Long1"); inOrder=true; } } } protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time) { if(Position.MarketPosition==MarketPosition.Flat) { Lowest=double.MaxValue; inOrder=false; } }
BUT it didn't happen that way!!! The strategy only place an order EVERY ONCE IN A LONG WHILE!!! And it's NOT from the lowest value where I want it to be!!!
PLEASE tell me where did I do wrong and how to fix it!!!
Thank you very VERY much! God bless you!!!
Comment