How do I reference a foreign ticker in my buy and sell signals

/* For example, a peak of a trough condition within a foreign ticker 
Current code is:  */
Buy  = daysback > 4 AND turn < 0 AND C > Ref(C,-1) ;
Sell = Cross(Slope<0,Slope>0) OR  turn >  0 ;

Is this what you're trying to do ?

http://www.amibroker.com/kb/2014/09/20/broad-market-timing-in-system-formulas/

3 Likes

/* Thanks so much travick. With your help I have been able to achieve my aims even though it has been a little different than I had expected. I could not figure how to incorporate the foreign signal into my ticker Buy/Sell code but that doesn’t really matter as I have been able to display the result along with the ticker data that I view prior to making a Buy.
For the record, I run EOD with the below code through Analysis/Explore to view latest Buy/Sell recommendations and then select the analysis chart from here.
The two charts:
Market: is where the Foreign XAO trend is displayed. Also shown is the Ticker data and the XAO overlay.
Analysis: shows daily Buy/ Sell Recommendations.*/`


  _SECTION_BEGIN("ElliottWave-Buy-Sell-Troughs. My Portfolio");

graphXSpace=Param("GraphXSpace",15,-50,50,1);
SetBacktestMode( backtestRegularRaw );

SECUpColor=ParamColor("SEC-UpColor",colorGreen); 
Sens=Param("Sens",4.75, 0.5, 15, 0.25); 
BarsSincePeak=BarsSince(Zig(C,Sens)==Peak(C,Sens)); 
BarsSinceTrough= BarsSince(Zig(C,Sens)==Trough(C,Sens)); 
BarsSinceTurnpoint=Min(BarsSincePeak,BarsSinceTrough); 
Daysback = ValueWhen(BarsSinceTurnpoint==0,(Max(PeakBars(C,Sens,1),TroughBars(C,Sens,1))))+1; 
Turn =ValueWhen(BarsSinceTurnpoint==0,LinRegSlope( Close, Daysback)); 
Slope= ValueWhen(BarsSinceTurnpoint==0,turn,0);
Turnt = WriteIf (Turn > 0 ,"Ticker  = Sell","Ticker = Buy");
printf("\n "+ Turnt);

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Small Elliott Wave
Change = 5;

Peak1 =( peak(Close,Change,1) ); 

P = ParamField( "ZIG Price field" );
change = Param("% change",1.0,0.25,25,0.25);
Color1 =(ParamColor("Smaller Elliott Wave1",colorlightgrey));
Plot( zz=DEMA(Zig(P, change),1), _DEFAULT_NAME(), Color1, styleLine) ;
 
Color2 =(ParamColor("Smaller Elliott Wave2",Colordarkblue ));
Plot( zz=DEMA(Zig(P, change),2), _DEFAULT_NAME(), Color2, styleLine) ;
 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Large Elliott Wave
P1 = ParamField( "ZIG Price field" );
change1 = Param("% change1",4.5,0.25,25,0.25);  // Param( ''name'', defaultval, min, max, step, sincr = 0 ) 
Optimizechange1 = Optimize( "Change1", 5, 1, 30, 2 );   //Optimize("Name", DefaultValue, MinValue, MaxValue, StepValue)
change2 = Param("% change2",6.0 ,1.0 ,12.0,0.25);  // Param( ''name'', defaultval, min, max, step, sincr = 0 ) 

P1 = ParamField( "ZIG Price field" );
change1 = Param("% change1",4.5,0.25,25,0.25);
 
Color3 =(ParamColor("Larger Elliott Wave1",coloryellow));
Plot( zz=TEMA(Zig(P1, change1),1), _DEFAULT_NAME(), Color3, styleLine) ;
 
Color4 =(ParamColor("Larger Elliott Wave2",colorRed));
Plot( zz=TEMA(Zig(P1, change1),2), _DEFAULT_NAME(), Color4, styleLine) ;
 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Buy  = daysback > 4 AND turn < 0 AND C > Ref(C,-1);       
Sell = Cross(Slope<0,Slope>0) OR  turn >  0 ;

Buy  = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
           
Plot( C, "", colorDefault, styleBar ); // Plots the chart 
PlotShapes(IIf(Buy,  shapeCircle,  shapeNone),colorblue,       0,L, Offset= -70);  
PlotShapes(IIf(Buy, shapeHollowCircle,  shapeNone),colorwhite, 0,L, Offset= -70);                   
PlotShapes(IIf(Buy,  shapeUpArrow, shapeNone),colorwhite,      0,L, Offset=-58); 
PlotShapes(IIf(Sell, shapecircle,  shapeNone),colorred,        0,H, Offset= 60); 
PlotShapes(IIf(Sell, shapeHollowCircle,  shapeNone),colorwhite,0,H, Offset= 60);                       
PlotShapes(IIf(Sell, shapeDownArrow,shapeNone),colorblue,     0,H, Offset= -46); 

if(Status("action") == actionExplore);

Filter = Buy OR (Sell AND InWatchListName("1. My Stocks"));
//Filter = ( Buy OR Sell );
//Filter = ( BuyS OR SellS AND InWatchListName("1. My Stocks"));

// Comment Only -Add Signal Dates and Prices Headings
average = (H+L+C)/3;
SetOption("NoDefaultColumns", True);
AddTextColumn(Name(), "TICKER");
AddColumn(DateTime(), "Signal Date", formatDateTime);
AddColumn( IIf( Buy, BuyPrice, Null ),   "Buy Signal Close",  1.3, textColor = colorWhite, bkgndColor = colorGreen );
AddColumn( IIf( Sell, SellPrice, Null ), "Sell Signal Close",  1.3, textColor = colorWhite, bkgndColor = colorred );
AddColumn(iif(Buy,Average ,null),"BuyPrice=Days Ave ",1.3,textColor = colorblack, bkgndColor = colorlightblue );
AddColumn( Ref( DateTime(), 1 ), "next day DT", formatDateTime );


// Comment Only -Add Prices and Next day PricesLastClose = EndValue(C);
LV = LastValue(C);
AddColumn(LV,"Last Bar Close ",1.3,textColor = colorblack, bkgndColor = colorlightGrey );
AddColumn(ref(O,1),"ND Open ",1.3,textColor = colorblack, bkgndColor = colorGreen );
AddColumn(ref(H,1),"ND High ",1.3,textColor = colorblack, bkgndColor = colorGreen );
AddColumn(ref(L,1),"ND Low ",1.3,textColor = colorblack, bkgndColor = colorGreen );
AddTextColumn(FullName(), "  Name "); 


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Title = 
 
"\n" + 
//Switch to S&P symbol
//
SetForeign( "XAO" );
SECUpColor=ParamColor("SEC-UpColor",colorGreen); 
Sens=Param("Sens",4.75, 0.5, 15, 0.25); 
BarsSincePeak=BarsSince(Zig(C,Sens)==Peak(C,Sens)); 
BarsSinceTrough= BarsSince(Zig(C,Sens)==Trough(C,Sens)); 
BarsSinceTurnpoint=Min(BarsSincePeak,BarsSinceTrough); 
Daysback = ValueWhen(BarsSinceTurnpoint==0,(Max(PeakBars(C,Sens,1),TroughBars(C,Sens,1))))+1; 
Turn =ValueWhen(BarsSinceTurnpoint==0,LinRegSlope( Close, Daysback)); 
Slope= ValueWhen(BarsSinceTurnpoint==0,turn,0);
printf("\n");
Turnx = WriteIf (Turn > 0 ,"XAO is Trending Down","XAO is Trending Up");
printf("\n XAO =  "+ Turnx);
PlotForeign( "XAO", "", colorBlue, styleline | styleOwnScale);
RestorePriceArrays(); 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Define Font Details as seen on Screen
//FS1 = Param( "Font Size", 18, 14, 100, 1 );//Font Size
GfxSelectFont( "Times New Roman", 18, 700, True ); //Font Type
GfxTextOut( turnx    , 120 , 160 );
GfxTextOut( turnt    , 400 , 160 );

FS = Param( "Font Size", 14, 14, 100, 1 );//Font Size
GfxSelectFont( "Times New Roman", FS, 700, True ); //Font Type
GfxSetBkMode( colorWhite) ; 
gfxSetBkMode( colorred );//Font Background Color
GfxSetTextColor( ParamColor( "Color", colorWhite ) );//Font Color
Hor = Param( "Horizontal Position", 140, 1, 1200, 1 );//Horizontal Sreen Start Position
Ver = Param( "Vertical Position", 50, 1, 830, 1 );//Vertical Screen Start Position


//Writes Ticker, Name and Volume Commments
GfxTextOut( Name(), Hor-20, Ver-20 );
GfxTextOut( fullName(), Hor+40, Ver-20 );
GfxTextOut( "Vol 1000s = " + V/1000, Hor-20 , Ver +0 );// Specifies the String to be written

GfxTextOut( "ElliotWave Buy&Sell-Troughs. My Portfolio   " , Hor-20 , Ver+50 ); 
GfxTextOut( "For use with My Portfolio Only   " , Hor-20 , Ver+70 );


//Write Current Bar Prices and Headings
GfxTextOut( "Current Bar .",  Hor+470 , Ver-25 );
//GfxTextOut( "Elliott-Trade-Optimised " , Hor+390 , Ver -25);
GfxTextOut( "O= " + O, Hor+600, Ver-25  );
GfxTextOut( "H= " + H, Hor+600, Ver  );
GfxTextOut( "L= " + L, Hor+600 , Ver+25 ); 
GfxTextOut( "C= " + C, Hor+600 , Ver+50 ); 
GfxTextOut( "Average = " + Average, Hor+547 , Ver+75 ); 

yc = Ref(Close,-1);
Move = c-yc; 
Change = Prec(Move / C *100,3);
GfxTextOut( "Change = " +   Change  + " % ",   Hor+548, Ver + 100 );
GfxTextOut( ""+ Date(),  Hor+730 , Ver-25 );//Writes The Date 
//Current Values
LastOpen = LastValue (O);
LastLow = LastValue (L);
LastHigh = LastValue (H);
LastClose = LastValue (C);
LastAverage = (LastValue(C+H+l))/3; 
LastChange = LastValue (ref(C,-1));

//EndPrice Values
LV = LastValue (LastClose,1);  // Returns Last Bar Value 
LVM = TimeFrameGetPrice( "C", inDaily, -1 );
LVM1 = LastValue ( LVM, 1 );	 // Returns Last Bar Value Less "1" Day
MoveF = Prec( LV - LVM1, 3 ); //Subtracts Last Day price from Previous price and Sets decimal precision to 3 decimal places
DayCI = LastValue ( LVM, 1 );	 // Returns Last Bar Value Less "1" Day
LastChange = Prec( ( MoveF/ LVM1 ) * 100, 2 ); // Percent move from Yesterday to today

//Writes Last Bar Prices and Headings
LastDate = WriteVal(lastvalue( Datetime()),formatdatetime);
GfxTextOut( "Last Bar     O= " + LastOpen, Hor+880, Ver-25  ); //Returns Last Bar Values
GfxTextOut( "    H= " +    LastHigh, Hor+950, Ver  );
GfxTextOut( "    L= " +    LastLow, Hor+950 , Ver+25 ); 
GfxTextOut( "    C= " +    LastClose, Hor+950 , Ver+50 ); 
GfxTextOut( "Average = " + LastAverage, Hor+915 , Ver+75 ); 
GfxTextOut( "LastChange = " +   LastChange + " % ",  Hor+920, Ver + 100 );
GfxTextOut( "" + LastDate, Hor+1080 , Ver-25 );
gfxSetBkMode( colorred );//Font Background Color 
GfxSetTextColor( ParamColor( "Color", colorred ));

SetSortColumns(-2); 
_SECTION_END();

/Forgot to include charts/![Market|690x431](upload://cAnalysis 8F2vbMcX9VC4LErXgFjLJPCujL.jpeg)