Below I have included my code. I am simply trying to test the value from my oscillator for bar0 and compare it to bar1. I believe I have everything correct, but for some reason, when it goes into my "if" test, it doesn't draw a dot and only prints my test text. Also, on my chart, I see an entry, followed by an immediate exit at same price.
I have commented out SetStopLoss everywhere else.
What I want is to move my StopLoss to the high or low of the last bar if my condition is met. I would appreciate any help.
Thanks,
BEGIN CODE:
if (Position.MarketPosition == MarketPosition.Long)
{
if (bar0 < bar1) // If my osc reading for last bar, is less than 2 bars ago.
{
DrawDot("L1Break" + CurrentBar, false, 0, 0, Color.Green);
SetStopLoss("L1", CalculationMode.Price, Low[1], false);
Print("L1Break Bar0 Is Less than Bar1 and we are Long"}
}
if (Position.MarketPosition == MarketPosition.Short)
{
if (bar0 > bar1) // If my osc reading for last bar, is greater than osc reading 2 bars ago.
{
DrawDot("S1Break" + CurrentBar, false, 0, 0, Color.Red);
SetStopLoss("S1", CalculationMode.Price, High[1], false);
Print("S1Break Bar0 Is Greater than Bar1 and we are Short");
}
}
Comment