Simple Coding Help - No Promise.

mtftrader

Code:
Cond1 = <Some boolean condition>;
Cond2 = <Some other boolean condition>;
Cond3 = <yet other boolean condition>;
.....
CondN = <altogether different boolean condition>;

ConditionSoup = Cond1 + Cond2 + Cond3 ..... + CondN;

PlotShapes((ConditionSoup == 2) * shapeCircle, colorGreen, 0, H, 45 );


This is the all condition i got( in pink font )
and For counting , number of elements (In red font, big size letter) , it's not working
Code is below on the link http://www.traderji.com/amibroker/90119-simple-coding-help-no-promise-451.html#post1178702
I've to change only one line if(Sum(b)= 2)PlotShapes( shapeCircle*up , colorGreen, 0, H, 45 ); //i'm missing something
 
Last edited:
Up = C>O; Up1 = C1>O1;
Ref -1 shift the condition to the front.
The last front is BarCount-1, the previous condition at BarCount-2 will be shown in BarCount-1.
There're formula (afl) which work fine when used same for( b = 0; b < BarCount; b++ ) and ref(, -1) , it just work fine on current timeframe.
I will post this stuff later..


Do you know, how to calculate number of elements?
Code and Number of elements : http://www.traderji.com/amibroker/90119-simple-coding-help-no-promise-451.html#post1178702

When there is two numbers (any two different numbers as in loop) under it..
I want to plot shape on candle. like ..
if(Sum(b)= 2)PlotShapes( shapeCircle*up , colorGreen, 0, H, 45 );
What need to be changed in this afaik only one line need to be changed ?
 
Last edited:
Hello all,

I got this code from a site. but it shows error( Syntax error"QuantX_Buy" is undefined)

can anybody please guide me


Code:
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );


A = Wilders( H,34 );
B = Wilders( L,34 );


x= Ref(A,-34);
y= Ref(B,-34);

D=.0009;
xt=x+x*D;
xb=x-x*D;

yt=y+y*D;
yb=y-y*D;

/* Buy or Sell Condition */
Buy = Cross(Close,xt);
Sell = Cross(yt,Close);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

AlertIf( Buy, "SOUND C:\\Windows\\Media\\notify.wav", "Audio alert", 2);
AlertIf( Sell, "SOUND C:\\Windows\\Media\\tada.wav", "Audio alert", 2 );

Filter = Buy OR Sell;
/* Exploration Parameters */
AddTextColumn( FullName(), "Company Name" );
AddColumn( Buy, "Buy", 1 );
AddColumn( Sell, "Sell", 1 );
AddColumn( C, "Close", 1.3 );
AddColumn( H, "High", 1.4 );

Title = EncodeColor(colorWhite)+ "Mahadev" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+ 
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorWhite)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50); 
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50); 
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
_SECTION_END();

_SECTION_BEGIN("ATS");
 GfxSetOverlayMode(1);
 GfxSetTextAlign( 0 );// center alignment
 GfxSetTextColor( ColorHSB( 120,240,160) );
 GfxSetBkMode(0); // transparent
 GfxSelectFont("Arial", 13);
 GfxTextOut( "AFL Integrated", 5,30 ); //you can change your own display name

 if(Buy[LastValue( BarIndex()-1 )] ==1){QuantX_Buy(NumToStr(LastValue(Ref(DateTime(),-1),True),formatDateTime),"ALL");}
 if(Sell[LastValue( BarIndex()-1 )] ==1){QuantX_Sell(NumToStr(LastValue(Ref(DateTime(),-1),True),formatDateTime),"ALL");}
 _SECTION_END();

_SECTION_BEGIN("Shiv2daybrkOut");

SetChartOptions(0,chartShowArrows|chartShowDates);


LClose = Close;

// Calculations for Buy and Sell Signals

DC1=TimeFrameGetPrice( "C", inDaily, -1);
DC2=TimeFrameGetPrice( "C", inDaily, -2);
DH1=TimeFrameGetPrice( "H", inDaily, -1);
DH2=TimeFrameGetPrice( "H", inDaily, -2);
DL1=TimeFrameGetPrice( "L", inDaily, -1);
DL2=TimeFrameGetPrice( "L", inDaily, -2);
DO1=TimeFrameGetPrice( "O", inDaily, -1);
DO2=TimeFrameGetPrice( "O", inDaily, -2);
MaxH=Max(DH1,DH2);
MinL=Min(DL1,DL2);

Plot(MaxH,"2 Day High",colorGreen,styleLine);
Plot(MinL,"2 Day Low",colorRed,styleLine);

Plot_Range1 = (TimeNum() >= 091500 AND TimeNum()<= 153000) AND (DateNum()==LastValue(DateNum()));

mf = Param("Percentage",0.5,0.1,5,0.1);

wDay = Param("Scan Day",LastValue(Day()),1,31,1);

ORhigh = MaxH*(1-mf/100);
ORlow = MinL*(1+mf/100);

BreakOut = IIf(LClose>=ORhigh, LClose, 0);
breakDown = IIf(LClose<=ORlow, LClose, 0);

COL=IIf(BreakOut,colorGreen,IIf(breakDOWN,colorRed,Null));
Plot(C,"",COL,64);

//_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorLavender ), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick | styleNoLabel, maskHistogram  ), 2 );
//_SECTION_END();


//vr=ParamToggle("Plot Daily High/Low","Yes|No" ,1);
//if(VR  == 0)
//{
//Plot(FourDayHigh,"High Breakout", ParamColor("Hi Color",colorBlue));
//Plot(FourDayLow,"Low Breakout", ParamColor("Low Color",colorRed));
//Plot(ORHigh,"ORH", ParamColor("ORHi Color",colorBlue),32);
//Plot(ORLow,"ORL", ParamColor("ORLow Color",colorRed),32);
//Plot(P,"PIVOT", ParamColor("P Color",colorTan),8);
//Plot(R1,"", ParamColor("R1 Color",colorGreen),1);
//Plot(R2,"", ParamColor("R2 Color",colorGreen),1);
//Plot(S1,"", ParamColor("S1 Color",colorLightOrange),1);
//Plot(S2,"", ParamColor("S2 Color",colorLightOrange),1);
//}

//Bprice=IIf(Buy,LClose,0); //Buying Price
//Sprice=IIf(Sell,LClose,0); //Selling Price

// Output of Exploration results and Alert of Buy and Sell Signals and Plotting of breakout and breakdown levels
//AddColumn(Bprice,"Buy price");
//AddColumn(BTarget1,"BT 1");
//AddColumn(BTarget2,"BT 2");
//AddColumn(sprice,"Sell price");
//AddColumn(STarget1,"ST 1");
//AddColumn(STarget2,"ST 2");

/*AddColumn(LClose,"CMP");
AddColumn(TwoDayHigh,"New High",1.2,colorDefault,colorDefault,90);
AddColumn(TwoDayLow,"New Low",1.2,colorDefault,colorDefault,90);
AddColumn(TodayHigh,"Today High",1.2,colorDefault,colorDefault,90);
AddColumn(TodayLow,"Today Low",1.2,colorDefault,colorDefault,90);
AddColumn(P,"Pivot",1.2,colorDefault,colorDefault,90);
AddColumn(ORHigh,"OR High",1.2,colorDefault,colorDefault,90);
AddColumn(ORLow,"OR Low",1.2,colorDefault,colorDefault,90);
AddColumn(Now(format=4),"Time Now",1.2,colorDefault,colorDefault,90);
AddColumn(TimeNum(),"Time Then",1.2,colorDefault,colorDefault,90);
AddColumn(Now(format=4)-TimeNum(),"Diff",1.2,colorDefault,colorDefault,90);*/

//AlertIf(Buy,"","Buy " + Name() + " above " + FourDayHigh + ", CMP: " + C + ", SL " + Prec(P,2) + ", Targets " + Prec(BTarget1,2) +","+Prec(BTarget2,2) + "," +Prec(BTarget3,2), 1);
//AlertIf(Sell,"","Sell " + Name() + " below " + FourDayLow + ", CMP: " + C + ", SL " + Prec(P,2) + ", Targets " + Prec(STarget1,2) +","+Prec(STarget2,2) + "," +Prec(STarget3,2), 2);

//Title = EncodeColor(colorBlue)+ "Two Day BreakOut( "+mf+")%" + " - " +  Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorBlue) +
// "  - " + Date() +" - "+"\n" +EncodeColor(colorGreen) +"Op-"+O+"  "+"Hi-"+H+"  "+"Lo-"+L+"  "+
//"Cl-"+C+"  "+ "Vol= "+ WriteVal(V)+"\n"+EncodeColor(colorDarkRed) +"-----------------------------system says----------------------------------------"+"\n";
//EncodeColor(colorDarkGreen)+
//WriteIf (Buy , "GO LONG / cover  at ="+C+"\n"+EncodeColor(colorRed) +"Stop- toadys low ="+DL+"\n"+
//EncodeColor(colorDarkRed));
//WriteIf (Short ,"EXIT LONG / short  at "+C+"\n"+EncodeColor(colorRed) +"Stop-todays high "+DH+"\n");
_SECTION_END();


//**************************************************************************************************************************************//

_SECTION_BEGIN("ATR Intraday Swing Trade");

period = Param("Period", 20, 1, 240, 1);
mult = Param("Multiplier",3.3 , 1, 240, 0.1);


// ATR Trading for 5 Minutes //

TimeFrameSet(in5Minute);

f=ATR(period);

VS[0] = Close[0];
trend[0] = 0;
HighC[0]=0;
Lowc[0]=0;

for( i = period+1; i < BarCount; i++ )
{

vs[i] = vs[i-1];
trend[i] = trend[i-1];
highC[i] = HighC[i-1];
lowc[i] = lowc[i-1];

if ((trend[i]>=0) && ( C[i] <VS[i] ))
{
trend[i] =-1;
HighC[i] = C[i];
lowc[i] = C[i];
}

if ((trend[i]<=0) && (C[i] >VS[i]))
{
trend[i]=1;
HighC[i] = C[i];
lowc[i] = C[i];
}

if (trend[i]==-1)
{
if (C[i]<lowc[i]) lowc[i] = C[i];
VS[i]= lowc[i]+ (mult*f[i]);
}


if (trend[i]==1)
{
if (C[i]>HighC[i]) HighC[i] = C[i];
VS[i]= HighC[i]-(mult*f[i]);
}

}

TimeFrameRestore();


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

_SECTION_BEGIN("default");
TimeFrameSet(inHourly);
HaClose =EMA((O+H+L+C)/4,6); 
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 ); 
HaHigh = Max( H, Max( HaClose, HaOpen ) ); 
HaLow = Min( L, Min( HaClose, HaOpen ) );
TimeFrameRestore();
HAopenf=TimeFrameExpand( Haopen, inHourly);  
Haclosef=TimeFrameExpand( Haclose, inHourly);
HaHighf=TimeFrameExpand( Hahigh, inHourly);
HaLowf=TimeFrameExpand( Halow, inHourly);
Color = IIf( Haopenf > Haclosef,4, IIf( Haopenf == Haclosef,colorYellow, 6));
_SECTION_END();

_SECTION_BEGIN("4");
Compress4= Param("Compression4",6,1,12,1); 
TimeFrameSet(Compress4* Interval());
HaClose4 =EMA((O+H+L+C)/4,6); 
HaOpen4 = AMA( Ref( HaClose4, -1 ), 0.5 ); 
HaHigh4 = Max( H, Max( HaClose4, HaOpen4 ) ); 
HaLow4 = Min( L, Min( HaClose4, HaOpen4 ) ); 
TimeFrameRestore();
HAopen4f=TimeFrameExpand( Haopen4, Compress4* Interval());  
Haclose4f=TimeFrameExpand( Haclose4, Compress4* Interval());
HaHigh4f=TimeFrameExpand( Hahigh4, Compress4* Interval());
HaLow4f=TimeFrameExpand( Halow4, Compress4* Interval());
Color4 = IIf( Haopen4f > Haclose4f,4, IIf( Haopen4f == Haclose4f ,colorYellow, 6));
_SECTION_END();

_SECTION_BEGIN("5minute");
TimeFrameSet(in5Minute);
HaClose5 =EMA((O+H+L+C)/4,6); 
HaOpen5 = AMA( Ref( HaClose5, -1 ), 0.5 ); 
HaHigh5 = Max( H, Max( HaClose5, HaOpen5 ) ); 
HaLow5 = Min( L, Min( HaClose5, HaOpen5 ) );
TimeFrameRestore();
HAopen5f=TimeFrameExpand( Haopen5, in5Minute);  
Haclose5f=TimeFrameExpand( Haclose5, in5Minute);
HaHigh5f=TimeFrameExpand( Hahigh5, in5Minute);
HaLow5f=TimeFrameExpand( Halow5, in5Minute);
Color5 = IIf( Haopen5f > Haclose5f,colorRed, IIf( Haopen5f == Haclose5f,colorYellow, colorGreen));
_SECTION_END();

Plot(VS, "Stop Loss",IIf(trend==1,10,11 ),styleThick);

mkol = IIf( Trend==1, colorGreen, colorRed);

Plot(2,"", Color5, styleOwnScale|styleArea|styleNoLabel, -0.5, 100);
Plot(2,"", Color4, styleHistogram+styleThick|styleOwnScale|styleNoLabel, -2, 100 );
Plot(2,"", Color,  styleOwnScale|styleArea|styleNoLabel, -4, 100 );

//Title = EncodeColor(colorBlue)+"Shiv Intraday ATR Trading System :-"+"  "+ Name() + "  "+ EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorBlue) + 
// " - " + Date() + "    MACD : "+ MACD() + ",   Signal : " + Signal() + "Current : " + LongExit +"," + ShortExit +"\n" +
//"Buy : "+ValueWhen(Buy,Close,1)+"   Sell : "+ValueWhen(Short,Close,1) +"  Signals : " + LongPrice + "  " + ShrtPrice + 
//EncodeColor(colorRed)+
//WriteIf (Buy , " GO LONG at "+C+"  ","")+
//WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+"  ","")+
//WriteIf (Short , " GO SHORT at "+C+"  ","")+
//WriteIf (Cover , " EXIT SHORT / Reverse Signal at "+C+"  ","")+"\n"+EncodeColor(colorBlue)+
//WriteIf(Buy , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
//WriteIf(Short  , "Total Profit/Loss for the Last trade Rs."+(ShortPrice-C)+"","")+
//WriteIf(Long AND NOT Buy, "Trade : Long - Entry price Rs."+(BuyPrice),"")+
//WriteIf(shrt AND NOT Short, "Trade : Short - Entry price Rs."+(ShortPrice),"")+"\n"+ 
//WriteIf(Long AND NOT Buy, "Current Profit/Loss Rs."+(C-BuyPrice)+"","")+
//WriteIf(Shrt AND NOT Short, "Current Profit/Loss Rs."+(ShortPrice-C)+"","");
_SECTION_END();

/////////////////////////////////           Trend Indicator on Background  ////////////////////////////////////////

function ZeroLagTEMA( array, period )
{
 TMA1 = TEMA( array, period );
 TMA2 = TEMA( TMA1, period );
 Diff = TMA1 - TMA2;
 return TMA1 + Diff ;
}
 
/////////////////////
// Heikin-Ashi code
HaClose = (O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
 
avp = Param("Up TEMA avg", 34, 1, 100 );
avpdn = Param("Dn TEMA avg", 34, 1, 100 );
 
// Velvoort is using not original, but modified Heikin-Ashi close
HaClose = ( HaClose + HaOpen + Max( H, HaOpen ) + Min( L, HaOpen ) )/4;
 
// up average
ZlHa = ZeroLagTEMA( HaClose, avp );
ZlCl = ZeroLagTEMA( ( H + L ) / 2, avp );
ZlDif = ZlCl - ZlHa;
 
keep1 = Hold( HaClose >= HaOpen, 2 );
keep2 = ZlDif >= 0;
keeping = keep1 OR keep2;
keepall = keeping OR ( Ref( keeping, -1 ) AND ( C > O ) OR C >= Ref( C, -1 ) );
keep3 = abs( C - O ) < ( H - L ) * 0.35 AND H >= Ref( L, -1 );
utr = keepall OR ( Ref( keepall, -1 ) AND keep3 );
 
// dn average
ZlHa = ZeroLagTEMA( HaClose, avpdn );
ZlCl = ZeroLagTEMA( ( H + L ) / 2, avpdn );
ZlDif = ZlCl - ZlHa;
 
keep1 = Hold( HaClose < HaOpen, 2 );
keep2 = ZlDif < 0;
keeping = keep1 OR keep2;
keepall = keeping OR ( Ref( keeping, -1 ) AND ( C < O ) OR C < Ref( C, -1 ) );
keep3 = abs( C - O ) < ( H - L ) * 0.35 AND L <= Ref( H, -1 );
dtr = keepall OR ( Ref( keepall, -1 ) AND keep3 );
 
upw = dtr == 0 AND Ref( dtr, -1 ) AND utr;
dnw = utr == 0 AND Ref( utr, -1 ) AND dtr;
 
Haco = Flip( upw, dnw );

if( ParamToggle("Trend Indicator in Background ?", "Yes / No")) 
{ 
if( ParamToggle("Chart Type", "Price with color back|HACO wave" ) )
{
 Plot( Haco, "Haco", colorRed );
}
else
{
 //Plot( C, "Close", colorBlack,
   //    ParamStyle( "Style", styleCandle, maskPrice ) );
 Plot( 1, "", IIf( Haco , colorPaleGreen, colorRose ),styleArea | styleOwnScale, 0, 1 );
}
}
else
{
Plot( C, "Close", colorBlack,ParamStyle( "Style", styleCandle, maskPrice ) );
}

// ****************************************************       Buy & Sell           *************************************

Buy = (LClose >= MaxH) AND (LClose > VS) AND LastValue(Day())==wDay; 
Short =(LClose <= MinL) AND (LClose < VS) AND LastValue(Day())==wDay; 

// Calculation of Stop Loss and Exit points
BuyPrice=ValueWhen(Buy,C,1);
ShortPrice=ValueWhen(Short,C,1);
BuyExit=BuyPrice*(1-1/100);
ShortExit=ShortPrice*(1+1/100);

Sell = (LClose < VS);
Cover = (LClose > VS);

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

PlotShapes(Buy*shapeUpArrow,5,0,L,-15);
PlotShapes(Sell*shapeHollowDownArrow,5,0,H,-15);
PlotShapes(Short*shapeDownArrow,4,0,H,-15);
PlotShapes(Cover*shapeHollowUpArrow,4,0,L,-15);

Filter=Buy OR Short OR Sell OR Cover;
AddColumn(IIf(Buy,66,43),"New Trade Bar", formatChar, colorWhite, bkcolor =IIf(Buy, colorGreen,2));
AddColumn(IIf(Short,83,43),"New Trade Bar", formatChar, colorWhite, bkcolor =IIf(Short, colorRed,2));
Thanks
 
Hello Friends

I am starting this thread for helping anyone who requires small changes in AFLs or AFL coding done for small / simple requirements that can be clearly defined.

What does not go is conversion . . . from Amibroker to anything else . . . or from anything else to Amibroker . . .

Debugging requested for copy/paste AFLs, Please don't post huge AFLs with zillions of lines of code for debugging

I will not be available for any conversions and I am not interested in debugging some-one else's copy/pasted work and lastly . . .
Not interested in hacking/craking any ones work . . .

Only if have a clearly definable task to be coded I maybe able to help . . . No Promises but will try within my limitations . . .


As an example, recently one of our friends wanted a motivational message to be included in his Charts,
I enjoyed doing that, as i could easily empathize with why he wanted that . . .


Cheers

:) Happy
Dear Happy,

Thanks for yr kind ad to help new Amibroker coders like me.
I have already completed the excel format of my trader's navigator which i use to trade on the nigerian stock exchange.
Can i send you my attempts at afl coding?

I remain.

Mike-Ekwueme (respartner)
 
This is the all condition i got( in pink font )
and For counting , number of elements (In red font, big size letter) , it's not working
Code is below on the link http://www.traderji.com/amibroker/90119-simple-coding-help-no-promise-451.html#post1178702
I've to change only one line if(Sum(b)= 2)PlotShapes( shapeCircle*up , colorGreen, 0, H, 45 ); //i'm missing something


mtftrader

My reply to you was based on the same post (post1178702) you've referred to again.

I did not understand the code that was written in that post, but I did get some idea of your requirements from the images posted and hence I gave a starter template.

I cannot spend time debugging your code here.
 
Quantx functions are used by one of the broker's plugin for sending orders from amibroker to a trading terminal. It is not just DLL that you can copy and use. You will also need a valid trading account with the broker for it to work.

Hello all,
I got this code from a site. but it shows error( Syntax error"QuantX_Buy" is undefined)
can anybody please guide me
....

Thanks
 
Quantx functions are used by one of the broker's plugin for sending orders from amibroker to a trading terminal. It is not just DLL that you can copy and use. You will also need a valid trading account with the broker for it to work.
Hello mastermind sir,
Thanks for your reply.
Can we use the code by removing quantx function. (Or) the logic code is hidden in the DLL file?

Thanks
 
Hello all,

I got this code from a site. but it shows error( Syntax error"QuantX_Buy" is undefined)

can anybody please guide me


Thanks
Hello mastermind sir,
Thanks for your reply.
Can we use the code by removing quantx function. (Or) the logic code is hidden in the DLL file?

Thanks
You can comment out both line that use QuantX_Buy and QuantX_Sell. AFL will work but do not function for what QuantX is used. (may be auto trading)
 

Similar threads