PDA

View Full Version : avoid being filled in gaps...?


gsmaster
07-13-2007, 01:06 PM
Hi everyone,

I have a small issue that I cannot find how to deal with it... when my strategy gets backtested it happens that after setting a EntryStopShort() at lets say the low of a bar then if the next day`s bar opened in a big gap it unrealistically creates a FILL at the low of the bar .... I would like to be able to indicate the strategy NOT to fill any entry if the next days open with a gap out of the price... is that possible??

Another issue I have is by doing a SetStopLoss() ... I am doing the following piece of code after detecting my signal... awkwardly the setstoploss for the SHORT works but not the one for the LONG :confused:

if (condition)
{
EnterLongStop(DefaultQuantity, High[0] + 1 * TickSize, "Outlong");
EnterShortStop(DefaultQuantity, Low[0] - 1 * TickSize, "Outshort");
SetStopLoss("Outlong",CalculationMode.Price,Low[0]-1*TickSize,true); // this one does not work :S
SetStopLoss("Outshort",CalculationMode.Price,High[0]+1*TickSize,true); // This one works
}

can you give some pointers?

thanks :D

GS

NinjaTrader_Ray
07-13-2007, 02:08 PM
Issue 1) This can't be changed

Issue 2) Try putting the SetStopLoss() calls above the Enter() calls, does that make a difference?

gsmaster
07-13-2007, 02:50 PM
thanks for the tip, I just tried , it did not work... but its weird the short stop loss work the other not...

GS

NinjaTrader_Ray
07-13-2007, 02:56 PM
Strip down your strategy so that it only goes short. Are stop loss orders submitted?

richa61416
07-14-2007, 07:07 AM
In back testing I do realise that when the day changes, that could be an issue with some indicator triggering in correct results until they stabilise. Try restricting the time your strategy session starts, and extending you back testing times.
E.g. If you are back testing from 9am to 3.PM, then you may consider setting the sesssion to back test from the period 8.30 to 3.PM, then have your code in the On Bar Update, to exit if the time is < 9.am. If you were using a 1 Minute strategy, you could start the session from 9.25 to 3.Pm just give the strategy time to adjust to 1 bar for the day, before taking actions from it.

gsmaster
07-14-2007, 09:39 AM
Hi Support,

yes well I obviously tried to only do long (enter and setstoploss) or short even though the short stop loss works and the long still does not :S

GS

NinjaTrader_Ray
07-14-2007, 12:00 PM
What I can confirm is that the methods do work. I took a chunk of your code and put it into a bare bones strategy. SetStopLoss() is working as expected.

Import the attached strategy via File > Utilities > Import and use this as a starting point. Add your own logic step by step until it works as you expect it to.

gsmaster
07-14-2007, 02:38 PM
thanks I will ...

gsmaster
07-16-2007, 12:44 PM
dear Support,

I have tried to fix the problem without success but I found something interesting that might help you help me :)

look at the code:

if (conditiontoenterlimits)
{
DrawDot("tdot" + CurrentBar, 0, High[0] + 1 * TickSize, Color.Blue);
highxx=High[0];
lowxx=Low[0];
flag=1;
SetStopLoss("short",CalculationMode.Price,High[0]+1*TickSize,true);
SetStopLoss("long",CalculationMode.Price,Low[0]-1*TickSize,true);
EnterLongStop(DefaultQuantity, High[0] + 1 * TickSize, "long");
EnterShortStop(DefaultQuantity, Low[0] - 1 * TickSize, "short");
}


if (flag==1)
{

if (conditiontoexitlong==true)
{
DrawDiamond("MyDiamond" + CurrentBar, 0, High[0] + 2 * TickSize, Color.Blue);
ExitLong("Exitlong", "long");
flag=0;

}


if (conditiontoexitshort==true)
{
DrawDiamond("MyDiamond" + CurrentBar, 0, High[0] + 2 * TickSize, Color.Blue);
ExitShort("Exitshort", "short");
flag=0;

}
}


ok what I have found is this,,, if I leave everything as is then setstoploss for the SHORTS will not work... but if I comment the conditiontoexitshort block then BOTH stoploss for longs and shorts will work.

If I uncomment the conditionexitshort and comment conditiontoexitlong then I still get the same stoploss error...

in conclusion I think something is wrong with conditiontoexitshort the problem is that I cannot see the error... any ideas?? :D

thanks
GS

NinjaTrader_Ray
07-16-2007, 02:12 PM
Thanks. Could you send me your strategy so I can test it on my end? Send to support at ninjatrader dot com and in the subject include "For Ray" and reference this post. Thanks.