Check direction simple moving average
Check direction simple moving average
31 Aug 2020, 19:37
how do i check the direction of the moving averages in real time and if they go high i go buy if they go low i sell?
Thanks a lot
Replies
luca.tocchi
02 Sep 2020, 20:03
RE: RE:
firemyst said:
luca.tocchi said:
how do i check the direction of the moving averages in real time and if they go high i go buy if they go low i sell?
Thanks a lot
You get the current value of the MA and can compare it to the previous value to see if it's increasing or decreasing.
//example pseudo-code if (ma.Result.Last(0) > ma.Result.Last(1)) //open long position else if (ma.Result.Last(0) < ma.Result.Last(1)) //open short position else //the ma values are equal. What do you want to do?
Yes sure
but I have to check 3 moving averages, if all 3 are up go buy, if all 3 are down go sell
but if at least one of these averages goes in the opposite direction, the program must wait for all three to go in the same direction
I would be grateful if you could help me
@luca.tocchi
firemyst
09 Sep 2020, 06:18
RE: RE: RE:
luca.tocchi said:
firemyst said:
luca.tocchi said:
how do i check the direction of the moving averages in real time and if they go high i go buy if they go low i sell?
Thanks a lot
You get the current value of the MA and can compare it to the previous value to see if it's increasing or decreasing.
//example pseudo-code if (ma.Result.Last(0) > ma.Result.Last(1)) //open long position else if (ma.Result.Last(0) < ma.Result.Last(1)) //open short position else //the ma values are equal. What do you want to do?
Yes sure
but I have to check 3 moving averages, if all 3 are up go buy, if all 3 are down go sell
but if at least one of these averages goes in the opposite direction, the program must wait for all three to go in the same direction
I would be grateful if you could help me
Then do the same thing for the 3 moving averages:
//example pseudo-code
if (ma1.Result.Last(0) > ma1.Result.Last(1)
&& ma2.Result.Last(0) > ma2.Result.Last(1)
&& ma3.Result.Last(0) > ma3.Result.Last(1))
//open long position
else if (ma1.Result.Last(0) < ma1.Result.Last(1)
&& ma2.Result.Last(0) < ma2.Result.Last(1)
&& ma3.Result.Last(0) < ma3.Result.Last(1))
//open short position
else
//the ma averages are all not going in the same direction. What do you want to do?
@firemyst
firemyst
01 Sep 2020, 17:55
RE:
luca.tocchi said:
You get the current value of the MA and can compare it to the previous value to see if it's increasing or decreasing.
@firemyst