Help in understanding code part

Hi,

I have this sample afl code that sends orders to an application

CODE

i want to make a different strategy that send orders to the application like the above code.
i am not able to understand which part of the code is responsible for order sending.
that i can use to send orders for my own strategy

Thanks

You should follow forum rules. Instead posting links to 3rd party sites you should use code tags and place the code inline.

sorry, I can't edit the post.
here's the code

GraphXSpace=1;
k = (GetPerformanceCounter()/10)%3000; 
p= 1;
Om=DEMA(Avg,p);
hm=DEMA(Avg,p);
lm=DEMA(Avg,p);
Cm=DEMA(Avg,p);
HACLOSE=(Om+Hm+Lm+Cm)/4;
HaOpen = AMA( Ref( HaClose, -1), 1);
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );
Hacol = IIf(HaClose>HaOpen, colorDarkGreen, colorDarkRed);
SetBarFillColor(Hacol);
PlotOHLC( HaHigh, HaHigh, HaLow, HaLow, " " + Name(), IIf(HaClose>HaOpen, colorBrightGreen, colorCustom12), styleCandle); //colorBlue, styleCandle );


p= 5;
Om=DEMA(Avg,p);
hm=DEMA(Avg,p);
lm=DEMA(Avg,p);
Cm=DEMA(Avg,p);
HACLOSE=C=(Om+Hm+Lm+Cm)/4;
HaOpen =O= AMA( Ref( HaClose, -1), 1);
HaHigh =H= Max( Hm, Max( HaClose, HaOpen ) );
HaLow = L=Min( Lm, Min( HaClose, HaOpen ) );
Hacol = IIf(HaClose>HaOpen, colorDarkGreen, colorDarkRed);
//SetBarFillColor(Hacol);
//PlotOHLC( HaHigh, HaHigh, HaLow, HaLow, " " + Name(), IIf(HaClose>HaOpen, colorBrightGreen, colorCustom12), styleCandle); //colorBlue, styleCandle );



_SECTION_BEGIN("DLL test");

SetPositionSize(1, spsShares);
SetBarsRequired(sbrAll, sbrAll);

DT = DateTime();
DN = DateNum();
TN = TimeNum();

t1 =100000;
t2 =230000;

function Asign(x)
{
y = Null;
for(i = 0; i < BarCount; i++)
{
y[i] = x;
}
return y;
}

grid_day = IIf(Day()!=Ref(Day(),-1),1,0);
Plot(grid_day,"",colorGreen,styleHistogram|styleDashed|styleNoLabel|styleOwnScale);


SLPT =35;

livesignal=2;// Optimize("Plugin",2,1,200,1);
sqofftime =233000;// ParamTime("SquareOff Time", "11:59:00 PM", 0);

REBYIN = Asign(False);
RESHIN = Asign(False);
REPLIM = 0;

DCLNTCH1();






Buy=Ref(Buy,-1);
Short=Ref(Short,-1);
Cover=Ref(Cover,-1);
Sell=Ref(Sell,-1);



/*
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
*/
BuyPrice=ValueWhen(Buy,O);
CoverPrice=ValueWhen(Cover,O);
ShortPrice=ValueWhen(Short,O);
SellPrice=ValueWhen(Sell,O);

LongTrue = Flip(Buy, Sell) || Sell;
ShortTrue = Flip(Short, Cover) || Cover;

Plot(IIf(LongTrue , BuyPrice, Null), "BuyPrice", colorGreen, styleDots|styleStaircase, Null, Null, 0, 1, 1);

Plot(IIf(ShortTrue, ShortPrice, Null), "ShortPrice", colorOrange, styleDots|styleStaircase, Null, Null, 0, 1, 1);




//Plot(BuyPrice, "BuyPrice", colorGreen, styleDots|styleStaircase);
//Plot(ShortPrice, "ShortPrice", colorOrange, styleDots|styleStaircase);

Candlecol=IIf(BarsSince(Buy)<BarsSince(Short) AND BarsSince(Buy)!=0,colorBlue,
  IIf(BarsSince(Buy)>BarsSince(Short) AND BarsSince(Short)!=0,4,1));
cc1=IIf(Buy,colorBlue,IIf(Short,colorRed,Candlecol));
SetBarFillColor(Cc1);

//Plot( C, "Price", colorDefault, styleCandle );

Buyshape = Buy * shapeUpArrow;
SellShape = Sell * shapeStar;
PlotShapes( Buyshape, colorBrightGreen, 0, Low );
PlotShapes( SellShape, colorRed, 0, High );

Shortshape = Short * shapeDownArrow;
CoverShape = Cover * shapeStar;
PlotShapes( Shortshape, colorOrange, 0, High, -30);
PlotShapes( CoverShape, colorTurquoise, 0, Low, -30 );
/*
Plot(BRK1, "BRK1", colorBrightGreen, styleDashed);
Plot(BRK2, "BRK2", colorRed, styleDashed);
Plot(BRK3, "BRK3", colorOrange, styleDashed);
Plot(BRK4, "BRK4", colorTurquoise, styleDashed);

*/
_SECTION_END();


dist = 2.5*ATR(10);
dist1 = 2.5*ATR(10);
for( i = 0; i < BarCount; i++ ) 
{ 
 if( Buy[i] ) 
 {
  PlotText( " BUY @" + BuyPrice[ i ] , i, L[ i ]-dist[i], colorWhite, colorBlack );
 }
 if( Short[i] )
 {
  PlotText( "Sell @" + O[ i ] ,i, H[ i ]+dist1[i], colorWhite, colorBlack );
 
 }
}



x=Param("xposn",1,0,1000,1);
y=Param("yposn",1,0,1000,1);

NDays=10;//Param("Number of Days",10,1,100,1); 
DayC=TimeFrameGetPrice("C",inDaily,-1);
NDaysDHLAvg=0;
for(i=1;i<=NDays;i++)
{
DayH=TimeFrameGetPrice("H",inDaily,-i);
DayL=TimeFrameGetPrice("L",inDaily,-i);
NDaysDHLAvg=NDaysDHLAvg+(DayH-DayL);
}
NDaysDHLAvg=NDaysDHLAvg/NDays;

ADM= NDaysDHLAvg; 
BuyTarget1= (0.25*ADM)+BuyPrice;
BuyTarget2= (0.45*ADM)+BuyPrice;
BuyTarget3= (0.70*ADM)+BuyPrice;
BuyStopLoss= BuyPrice-(0.25*ADM);
SellTarget1= SellPrice-(0.25*ADM);
SellTarget2= SellPrice-(0.45*ADM);
SellTarget3= SellPrice-(0.70*ADM);
SellStopLoss= SellPrice+(0.25*ADM);

//----------------------------------------------------------------Signals and Targets----------------------------
Long=Flip(Buy,Sell); 
Shrt=Flip(Sell,Buy);
//BUY
GfxSelectFont( "Arial Black", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorGreen );
GfxTextOut( WriteIf (Long AND NOT Buy, " BUY @ "+WriteVal(BuyPrice,1.2)+"  ",""), x+1, y+125);

//BUY STOPLOSS
GfxSelectFont( "Arial Black", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorOrange );
GfxTextOut( WriteIf (Long AND NOT Buy, " Stop Loss "+WriteVal(BuyStopLoss,1.2)+"  ",""), x+1, y+145);

//BUY TARGET 1
GfxSelectFont( "Arial Black", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorGrey40 );
GfxTextOut( WriteIf (Long AND NOT Buy, " Target 1: "+WriteVal(BuyTarget1,1.2)+"  ",""), x+1, y+165);

//BUY TARGET 2
GfxSelectFont( "Arial Black", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorGrey40 );
GfxTextOut( WriteIf (Long AND NOT Buy, " Target 2: "+WriteVal(BuyTarget2,1.2)+"  ",""), x+1, y+185);

//BUY TARGET 3
GfxSelectFont( "Arial Black", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorGrey40 );
GfxTextOut( WriteIf (Long AND NOT Buy, " Target 3: "+WriteVal(BuyTarget3,1.2)+"  ",""), x+1, y+205);






//SELL
GfxSelectFont( "Arial Black", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorRed );
GfxTextOut( WriteIf (Shrt AND NOT Sell, " SELL @ "+WriteVal(ShortPrice,1.2)+"  ",""), x+1, y+125);

//SELL STOPLOSS
GfxSelectFont( "Arial Black", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorOrange );
GfxTextOut( WriteIf (Shrt AND NOT Sell, " StopLoss "+WriteVal(SellStopLoss,1.2)+"  ",""), x+1, y+145);

//SELL TARGET 1
GfxSelectFont( "Arial Black", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorGrey40 );
GfxTextOut( WriteIf (Shrt AND NOT Sell, " Target 1: "+WriteVal(SellTarget1,1.2)+"  ",""), x+1, y+165);

//SELL TARGET 2
GfxSelectFont( "Arial Black", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorGrey40 );
GfxTextOut( WriteIf (Shrt AND NOT Sell, " Target 2: "+WriteVal(SellTarget2,1.2)+"  ",""), x+1, y+185);

//SELL TARGET 3
GfxSelectFont( "Arial Black", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorGrey40 );
GfxTextOut( WriteIf (Shrt AND NOT Sell, " Target 3: "+WriteVal(SellTarget3,1.2)+"  ",""), x+1, y+205);

//----------------------------------------------------------------Achieved Targets and Stl----------------------------

GfxSelectFont( "Arial", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorGreen );
GfxTextOut( WriteIf (Long AND NOT Buy AND BuyTarget1<C AND NOT Sell AND NOT Shrt, "TGT1 Hit ("+(WriteVal(BuyTarget1-BuyPrice,1.2))+")  ",""), x+170, y+165);

GfxSelectFont( "Arial", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorGreen );
GfxTextOut( WriteIf (Long AND NOT Buy AND BuyTarget2<C AND NOT Sell AND NOT Shrt, "TGT2 Hit ("+(WriteVal(BuyTarget2-BuyPrice,1.2))+")  ",""), x+170, y+185);

GfxSelectFont( "Arial", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorGreen );
GfxTextOut( WriteIf (Long AND NOT Buy AND BuyTarget3<C AND NOT Sell AND NOT Shrt, "TGT3 Hit ("+(WriteVal(BuyTarget3-BuyPrice,1.2))+")  ",""), x+170, y+205);

GfxSelectFont( "Arial", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorGreen );
GfxTextOut( WriteIf (Shrt AND NOT Sell AND SellTarget1>C AND NOT Buy AND NOT Long, "TGT1 Hit ("+(WriteVal(SellPrice-SellTarget1,1.2))+")  ",""), x+170, y+165);

GfxSelectFont( "Arial", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorGreen );
GfxTextOut( WriteIf (Shrt AND NOT Sell AND SellTarget2>C AND NOT Buy AND NOT Long, "TGT2 Hit ("+(WriteVal(SellPrice-SellTarget2,1.2))+")  ",""), x+170, y+185);

GfxSelectFont( "Arial", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorGreen );
GfxTextOut( WriteIf (Shrt AND NOT Sell AND SellTarget3>C AND NOT Buy AND NOT Long, "TGT3 Hit ("+(WriteVal(SellPrice-SellTarget3,1.2))+")  ",""), x+170, y+205);

GfxSelectFont( "Arial", 10, 100, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorRed );
GfxTextOut( WriteIf (Long AND NOT Buy AND BuyStopLoss>C AND NOT Sell AND NOT Shrt, "SL Hit - Exit("+(WriteVal(BuyStopLoss-BuyPrice,1.2))+")  ",""), x+170, y+145);

GfxSelectFont( "Arial", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorRed );
GfxTextOut( WriteIf (Shrt AND NOT Sell AND SellStopLoss<C AND NOT Buy AND NOT Long, "SL Hit - Exit("+WriteVal(SellPrice-SellStopLoss,1.2)+")  ",""), x+170, y+145);


GfxGradientRect( 1, 1, 1400, 40, colorBlack, colorBlack);
GfxSetBkMode(0);
GfxSelectFont( "a", 18, 800, False );
GfxSetTextColor( colorGold );
GfxTextOut( " Pattern Scalper- Using Neural Network. ", x+300, y+10 );
GfxSelectFont( "Tahoma", 16, 800, False );
GfxSetTextColor( colorGold );
//GfxTextOut( Name(), x+120, y+10 );
GfxSelectFont( "Century Gothic", 15, 100, False );
GfxSetTextColor( colorGold );
GfxTextOut( Date(), x+1000, y+10 );
GfxSelectFont( "Comic Sans MS", 15, 500, False );
GfxSetTextColor( colorGold );
//GfxTextOut( Interval(2), x+275, y+10 );
//------------------------------------------------------------ H, L, O, C----------------------

//PI = 3.1415926; 




GfxSelectFont( "Arial Black", 10, 300, False );
GfxSetTextAlign( 0 );
GfxSetTextColor( colorGreen );
GfxSetBkMode(1); 
GfxSetTextColor(colorBrown); 
GfxTextOut("Note: This System is using neural networks, to Identify News Breakouts, Technical Breakouts, Range patterns & Flags.  In this chart , we are using Renko Candle's to avoid market Noises, Renko candle prices are slightly different between the regular candle's Price. No Need to Consider the regular candles Prices.", 1500-k, 40 ); 



RequestTimedRefresh(1);

_SECTION_BEGIN("AmigoTrends");
// If user want to use external targets/stop loss from afl, please unhide the below code and
// asign corresponding array values to it.

// LT1 = Null;		// Long Target1 External
// ST1 = Null;		// Short Target1 External

// LT2 = Null;		// Long Target2 External
// ST2 = Null;		// Short Targe2 External

// LT3 = Null;		// Long Target3 External
// ST3 = Null;		// Short Target3 External

// LSL = Null;		// Long Stoploss External
// SSL = Null;		// Short Stoploss External

AmigoC1(Open, High, Low, Close, Volume, Buy, Sell, Short, Cover);
_SECTION_END();

See this: How do I debug my formula? - using debugging techniques described there you can analyze any code. But even after 5 second of looking at that code I can say it is written poorly (see for example 'Asign' function that is pure nonsense. You don't need function and loop to do assignment. Equal sign does all the job). The code is also incomplete (calls undefined functions). So as it is now, it is useless.

It is better to start from scratch than trying to understand wrong code.

1 Like

@mightysteel115, you need to get your account verified. Search "verified" or "verified badge" and follow the steps.