So I attempted to code a strategy, which part of, is to only trade between 9h30-945am.
I am new to Ninjascript, and did attempt to code it myself.
I did have the condition "
(ToTime(Time[0]) >= 93000 && ToTime(Time[0]) <= 94500)"
which is an if condition, which says if its in that time frame ALL the other conditions are 'open' if not then the other conditions don't work.
Here is the image of the script placing trades on every single candle attached.
Here is my code with the conditions:
if
// All conditions only work between 930-945am!
(ToTime(Time[0]) >= 93000 && ToTime(Time[0]) <= 94500)
// Condition set 1: If DM+ crosses above DM- AND the open is less than yesterday's close> GO LONG
if (CrossAbove(DM(14).DiPlus, DM(14).DiMinus, 1)&& (ToTime(Time[0]) == 93000)
&& CurrentDayOHL().CurrentOpen[0] < PriorDayOHLC().PriorClose[0]);
{
EnterLong(DefaultQuantity, "");
}
// Condition set 2
if (CrossAbove(DM(14).DiMinus, DM(14).DiPlus, 1) && (ToTime(Time[0]) == 93000)
&& CurrentDayOHL().CurrentOpen[0] > PriorDayOHLC().PriorClose[0]);
{
EnterShort(DefaultQuantity, "");
}
// Condition set 3
if (Position.MarketPosition == MarketPosition.Long)
{
Variable0 = High[0] + ATR(14)[0] * TickSize;
Variable3 = Low[0] + -2 * TickSize;
}
// Condition set 4
if (Position.MarketPosition == MarketPosition.Short)
{
Variable1 = Low[0] - ATR(14)[0] * TickSize;
Variable2 = High[0] + 2 * TickSize;
}
}
Thanks! and have a great day.
Comment