Heikin Ashi of Foreign Ticker

Hi can you plz help me in this afl code

i want use Heikin Ashi of Foreign Ticker to generate signal on Main Chart

I.e. when Foreign Ticker turn red candle in Heikin Ashi It should give buy Signal on main chart

I dont know what going wrong

_SECTION_BEGIN("ABC");

SetForeign( "ForeignTickereHere" );

SetChartOptions(0,chartShowArrows | chartShowDates);

HaClose = (O + H + L + C)/4; 
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 ); 
HaHigh = Max( H, Max( HaClose, HaOpen ) ); 
HaLow = Min( L, Min( HaClose, HaOpen ) ); 
xDiff = (HaHigh - Halow) * 10000;



CondB8F = HaOpen < HaClose;
CondS8F = HaOpen > HaClose;
CondB9F = HaLow > ME;
CondS9F = HaHigh < ME;


//Plot(TL,"",colorPink,styleLine);
//Plot(BL,"",colorPink,styleLine);

CondB8F = HaOpen < HaClose;
CondS8F = HaOpen > HaClose;



P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style");
MBT =BBandTop( P, Periods, Width );
MBL= BBandBot( P, Periods, Width );

Foreign_atr = ATR(20);

RestorePriceArrays();

_SECTION_END();




_SECTION_BEGIN("heiken");
SetChartOptions(0,chartShowArrows | chartShowDates);

HaClose = (O + H + L + C)/4; 
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 ); 
HaHigh = Max( H, Max( HaClose, HaOpen ) ); 
HaLow = Min( L, Min( HaClose, HaOpen ) ); 
xDiff = (HaHigh - Halow) * 10000;
barcolor = IIf(HaClose >= HaOpen,colorBrightGreen,colorRed);
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", barcolor, styleCandle );
;
Plot(ME,"",colorBlue,styleLine);

Plot(TL,"",colorPink,styleLine);
Plot(BL,"",colorPink,styleLine);

CondB8 = HaOpen < HaClose;
CondS8 = HaOpen > HaClose;


Buy = Cover= CondS8F ;

 
Short= Sell=CondB8F ;

 
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
 
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
 
Long=Flip(Buy,Sell); 
Shrt=Flip(Short,Cover);

/* We use live prices here, as ValueWhen function gives negative price sometimes */
buyPrice = LastValue(C);
sellPrice = LastValue(C);

D= floor(10000/C);

SetPositionSize( 500, spsShares ); // max share that can be bought in rs10000 shares by default
 
PlotShapes(IIf(Buy, shapeUpArrow , shapeNone), colorBlue);
PlotShapes(IIf(Short, shapeDownArrow , shapeNone), colorBlack);

PlotShapes(IIf(Sell, shapeStar , shapeNone), colorBlue);
PlotShapes(IIf(Cover, shapeHollowSmallSquare , shapeNone), colorBlack);
    

_SECTION_END();

Moderator comment: added REQUIRED code tags

Kind regards
Sam

@Sam1, Happy to see some code here, unfortunately you forgot to use the Code Tags (</>) to help properly format the code and make it easier for other users to get your code and test it out.

When I try to check the code I get errors when referencing the "ME" variable.

Also, when you read more about debugging, you should find references to Explorations. I find the Explore feature a GREAT way to help me debug.

Lastly, you need to figure out what is going wrong or at least what is not working the way you think it should. When we know what or where you are getting the "wrong" result, we can either help you spot your coding error, or teach you how a particular function works that may help.

As @snoopy.pa30 pointed out, the code posted is incomplete (missing assigment to ME variable). If you need help, post complete code that actually runs How to ask a good question

_SECTION_BEGIN("ABC");

/* Here i will take foreign ticker ÄPPLE */

SetForeign( "ForeignTickereHere" );

SetChartOptions(0,chartShowArrows | chartShowDates);

HaClose = (O + H + L + C)/4; 
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 ); 
HaHigh = Max( H, Max( HaClose, HaOpen ) ); 
HaLow = Min( L, Min( HaClose, HaOpen ) ); 
xDiff = (HaHigh - Halow) * 10000;

/*This is to check candle red  or green*/

CondB8F = HaOpen < HaClose;
CondS8F = HaOpen > HaClose;

RestorePriceArrays();

_SECTION_END();




_SECTION_BEGIN("heiken");

/* This will be main Ticker Henkianshi let assume FACEBOOK */

SetChartOptions(0,chartShowArrows | chartShowDates);

HaClose = (O + H + L + C)/4; 
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 ); 
HaHigh = Max( H, Max( HaClose, HaOpen ) ); 
HaLow = Min( L, Min( HaClose, HaOpen ) ); 
xDiff = (HaHigh - Halow) * 10000;
barcolor = IIf(HaClose >= HaOpen,colorBrightGreen,colorRed);
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", barcolor, styleCandle );
;

CondB8 = HaOpen < HaClose;
CondS8 = HaOpen > HaClose;

/*if Foreign Ticker Apple gives red candle on  Henkianshi a Buy Signal should appear on main Ticker Facebook chart*/


Buy = Cover= CondS8F ;
Short= Sell=CondB8F ;

 
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
 
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
 
Long=Flip(Buy,Sell); 
Shrt=Flip(Short,Cover);

/* We use live prices here, as ValueWhen function gives negative price sometimes */

buyPrice = LastValue(C);
sellPrice = LastValue(C);

D= floor(10000/C);

SetPositionSize( D, spsShares ); // max share that can be bought in $ 10000 shares by default
 
PlotShapes(IIf(Buy, shapeUpArrow , shapeNone), colorBlue);
PlotShapes(IIf(Short, shapeDownArrow , shapeNone), colorBlack);

PlotShapes(IIf(Sell, shapeStar , shapeNone), colorBlue);
PlotShapes(IIf(Cover, shapeHollowSmallSquare , shapeNone), colorBlack);
    

_SECTION_END();

I am not a programmer just learning by doing Hit and trail method. Only thing i want is if a Foreign Ticker X gives a red or downward candle in Henkianshi candle a Buys signal should be given on main chart Y Ticker with which i am comparing.

@Sam1, The code (in code blocks - YEAH) is working.

Now, What is your issue? (Ask a good Question).

I suspect (Guess) it is that you can't see the signals or shapes on your plot.

Two issues I see:

  1. You are re-defining your CondB8F and CondS8F variables in the Heiken section.
  2. You are plotting the Shapes, without specifying their Y position.

Also, have you learned about Explorations yet? A VERY Valuable skill to help you debug your own code.

Hope these two hints will help you get what you want.