Page 1 of 1

Reversing position off MACD

Posted: 24 Oct 2013 14:11
by Crighton
I am trying to automate trading from a MACD. I have been able to automate the MACD to go 'long' with 'AutoOrder' when crossing above 0, but the 'AutoOrder' closes the position once crossing below the 0. I want it to rather reverse the position when crossing below the 0.

I am using the MACD_NEO in the 'Express' to do this, is there a way to modify this to reverse position instead of close? Or is there any other way to do this?

EXPRESS MACD_NEO

VARS
series myMACD(MACD.main), flag ;


CALCULATION


if (myMACD[1]>= 0) then flag = 1;
if (myMACD[1]< 0) then flag = -1;


INTERPRETATION

begin
if CrossesAboveThreshold(flag, 0.5) then sentiment = 100;
if CrossesbelowThreshold(flag, -0.5) then sentiment = 0;
end
plot (flag,blue,2);//@@@cs:221826-3389839-93083_cs@@@

Re: Reversing position off MACD

Posted: 24 Oct 2013 14:56
by WHS Support
Hello,

I'm not 100% sure of what is the purpose of this MACD_NEO in contrast to the normal MACD. But if you only want to go "Long" when MACD crosses above the zeroline and go "Short" when MACD crosses below the zeroline the following code should work:

Express MACD_ZeroCross

Vars

Series fastMA, slowMA, Signalline, MACD, Zeroline(0);

Input
$slowEMA(1, 200, 26),
$fastEMA(1, 200, 12),
$smooth(1, 200, 9);

Calculation
If IsFirstbar() then begin
ExpMovingAverage(c, fastMA, $fastEMA);
ExpMovingAverage(c, slowMA, $slowEMA);
end
MACD = fastMA-slowMA;
If IsFinalBar() then ExpMovingAverage(MACD, Signalline, $smooth);

Interpretation
begin
if CrossesAbove(MACD, zeroline) then Sentiment = 100;
if CrossesBelow(MACD, zeroline) then Sentiment = 0;
end

plot (MACD, lightmagenta, 1);
plot (Signalline, darkblue, 1);
plot (zeroline, grey, 1);
//-----------

In the designer bar please make sure that the "MetaSentimentor can close positions" box is checked.

Best regards,
Timo
WH SelfInvest

Re: Reversing position off MACD

Posted: 25 Oct 2013 22:02
by Crighton
Many thanks! :D