Reading manual is A MUST, was: Facing issues in using SetForign() function


Info: My indicator is a simple EMA crossover strategy with additional conditions related to PDI and MDI. To better understand it read the comments in my code.

issue: I plotted my indicator in banknifty symbol, then I copied it, removed the setforign() and restorepricearrays() functions, and plotted it in HDFC chart and then I compared the signals between them. I observed that some signals were matching while others were not. (Note: I made sure that the parameter were matching)

To replicate my issue make sure to keep the parameter in default


CODE:

SetForeign("HDFC-I.NFO");

SystemName = "114000 - On Off ---5 36";   
SysVer ="v2.1";   
SetFormulaName( SystemName );   
  
paraCounter = 1;   
_N(paraParam = "" + paraCounter + "." +  NumToStr(GetChartID(),1,false) + ".");   
   
_SECTION_BEGIN("Price");   
SetChartOptions(0,chartShowArrows|chartShowDates);   
_N(Title = StrFormat(SystemName + " " + SysVer + "    |    {{NAME}}    -    {{INTERVAL}}    {{DATE}}          Open: %.2f          High: %.2f          Low: %.2f          Close: %.2f (%.2f%%)          Volume: %.0f          {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ), V ));   
Plot( C, "Close", colorDefault, styleNoTitle | GetPriceStyle() );    
_SECTION_END();   

_SECTION_BEGIN(paraParam + "4.00  Indicators Parameters");     
dm_positive_range = Param("Dm+ Period", 29,5,150,1); 
dm_negetive_range = Param("Dm- Period", 275,90,290,1); 

//miscellaneous  
Plot_ma = Param("Plot EMA L",0,0,1,1); 
Plot_ma_s = Param("Plot EMA s",0,0,1,1); 
_SECTION_END();     



_SECTION_BEGIN("Long conditions");   
dm_posotive_greater_than_of = Param("6L. Dm + should be greater On/Off",1,0,1,1);
dm_posotive_greater_than = Param("6L. Dm + should be greater",34,3,40,1);   

dm_negetive_less_than_of = Param("7L. Dm - should be less than On/Off",1,0,1,1); 
dm_negetive_less_than = Param("7L. Dm - should be less than",64,20,160,1);  
_SECTION_END();   


_SECTION_BEGIN("shortwip conditions");   
dm_negetive_less_thans_of = Param("6ss. Dm - should be less than On/Off",1,0,1,1);  
dm_negetive_less_thans = Param("6ss. Dm - should be less than",115,20,160,1);   

dm_posotive_greater_thans_of = Param("6s. Dm + should be greater On/Off",1,0,1,1);
dm_posotive_greater_thans = Param("5ss. Dm + should be greater",32,-110,60,1);  
_SECTION_END();    

Buy_ma = EMA(Close,62); 
Sell_ma = EMA(Close,24); 
 
if(Plot_ma) 
	Plot(Buy_ma,"Buy EMA",colorWhite); 
 
if(Plot_ma_S) 
	Plot(Sell_ma,"Sell EMA",colorYellow); 

///////////////<dmi greater or less than>///////////////////////////////////   
dm_positive = PDI(dm_positive_range);   //Dm+
dm_negetive = mdi(dm_negetive_range);   //Dm-
///////////////</dmi greater or less than/>///////////////////////////////////   
 
if(dm_posotive_greater_than_of){  //Dm+ greater than condition for long
	dmp_greater_than_Long = dm_positive > dm_posotive_greater_than; 
 }
else
{
	dmp_greater_than_Long = 1;
}  

if(dm_negetive_less_than_of){    //Dm- lesser than condition for long
	dmn_lesser_than_Long = dm_negetive < dm_negetive_less_than; 
 }
else
{
	dmn_lesser_than_Long = 1;
}  

if(dm_negetive_less_thans_of){  //Dm- lesser than condition for Short
	dm_negetive_less_than_short = dm_negetive < dm_negetive_less_thans;
}
else
{
	dm_negetive_less_than_short = 1;
}

if(dm_posotive_greater_thans_of){  //Dm+ greayer than condition for Short
	dm_posotive_greater_than_Short = dm_positive > dm_posotive_greater_thans;
}
else
{
	dm_posotive_greater_than_Short = 1;
}
  
EMA_rule_Long = Close > Buy_ma; //Base rules
EMA_rule_Short = Close < SELL_ma; 
   
buytest =  Ref(dmp_greater_than_Long AND  EMA_rule_Long AND dmn_lesser_than_Long,-1);  //Ref function used to create trade delays
selltest = Ref(dm_negetive_less_than_short  AND EMA_rule_Short AND dm_posotive_greater_than_Short,-1);
covertest = buytest;   //This as done because this indicator is contineus ie it has no (no trade zone)
shortest = selltest;

Buy = buytest;
Sell = selltest;
Cover = covertest;
Short = shortest;

buy = ExRem( buy, sell );
sell = ExRem( sell, buy );
cover = ExRem( cover, short );
short = ExRem( short, cover );

PlotShapes(Buy * shapeUpTriangle, colorBrightGreen, 0, L, -48);   
PlotShapes(Buy * shapeUpTriangle, colorBlue, 0, L, -36);   
PlotShapes(Buy * shapeUpTriangle, colorBrightGreen, 0, L, -24);   
PlotShapes(Short * shapeDownTriangle, colorRed, 0, H, -48);   
PlotShapes(Short * shapeDownTriangle, colorBlue, 0, H, -36);   
PlotShapes(Short * shapeDownTriangle, colorRed, 0, H, -24);   
PlotShapes(Sell * shapeCircle, colorBrightGreen, 0, High, 12);   
PlotShapes(Cover * shapeCircle, colorRed, 0, Low, -12); 
 
BuyPrice = open;
SellPrice = Open;
ShortPrice = open;
CoverPrice = Open;

SetPositionSize(1,spsShares);

SetBarsRequired(sbrAll,sbrAll); //Turns off Quick afl

DEBUG = 0; 
 
GfxTextOut("DM+ value: ",20,280);		GfxTextOut(NumToStr(SelectedValue(dm_positive)),110,280); 
GfxTextOut("DM- value: ",20,300);		GfxTextOut(NumToStr(SelectedValue(dm_negetive)),110,300); 

RestorePriceArrays(True);


Read the manual, comments section in Foreign function:
https://www.amibroker.com/f?foreign

that explains what foreign/setforeign does

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.