I have a few problems, with storing the value of a variable or input, and changing the value of a variable or input.
So, i'm trying to create a strategy that will use the value of a fib extension to use it as a target, and the strategy is creating her own fibonnaci extensions, its working like this :
I have 3 input, where i place manually the 3 price level for the points of the extension (i'm not using the time), but, in a example where i can be long, but the price don't go right away with me, the price can break the low where the third point and input of the extension is, so the strategy need to readjust the point.
The idea, is that when the low is break, the third point of the extension will be change to the new actual low of Low[0], and if the new low is also break, it will keep adjusting, until i get stopped out, or that we have a real low.
Here's the code, and the explains below :
protected override void OnBarUpdate()
{
// Fib Extension tracé pour calculer le point de target
if (State == State.Historical);
{
ValeurAjustement3PointFibExtension = (Valeur3PointFibExtension);
Draw.FibonacciExtensions(this, @"FibAutoTrailStoplongshortFibonacci extensions_1", false, 0, Valeur1PointFibExtension, 0, Valeur2PointFibExtension, 0, Valeur3PointFibExtension);
}
// Si long, et que le troisième point de l'extension est plus basse que le deuxième, et que le troisième point est casser vers le bas, le troisième point continueras d'être changer sur le nouveau low après sa cassure.
if ((PositionAccount.MarketPosition == MarketPosition.Long)
&& (Close[0] < ValeurAjustement3PointFibExtension))
{
PlaySound(NinjaTrader.Core.Globals.InstallDir + @"\sounds\Alert1.wav");
if ( CurrentBar < 1)return;
RemoveDrawObject("FibAutoTrailStoplongshortFibonac ci extensions_1");
ValeurAjustement3PointFibExtension = (Low[0]);
Draw.FibonacciExtensions(this, @"FibAutoTrailStoplongshortFibonacciAjustement extensions_1", false, 0, Valeur1PointFibExtension, 0, Valeur2PointFibExtension, 0, ValeurAjustement3PointFibExtension);
}
What i did, is that we have the basic public double Valeur3PointfFibExtension, the point that could need a adjustment and where we set the price level before, and the private double ValeurAjustement3PointFibExtension, take the value of Valeur3PointFibExtension. What i'm trying to do, is that if the low of ValeurAjustement3PointFibExtension is broken, the price will take the new actual low, but the problem, is that, the value is set to the Low[0], and in my mind, since to be trigger, we need to have the price that go below the value of the double, the change in the value will not happen, and stay at the exact low.
But the strategy, dont keep in memory the value that didn't get break, and will only set the value to the low of the open bar, since the = (Low[0]) is permanent.
So, is there a way to either, modify the value of ValeurAjustement3PointFibExtension each time the If is triggered, and that the value will stay the same and not move if the if is not triggered, even if there is new bars created (i found the Value.Set option, but i dont think its working on NT8). Or, to keep in memory the value that didn't get break for ValeurAjustement3PointFibExtension.
Thanks a lot ! If you need more of the code, its not a problem
Ps : at a certain point, the strategy could not compile without if ( CurrentBar < 1)return; and i understand that its really important, but why is it important, and how do is it work ?
Comment