25.10.2016 Views

Expert Advisor Programming by Andrew R. Young

Expert Advisor Programming by Andrew R. Young

Expert Advisor Programming by Andrew R. Young

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

EXPERT ADVISOR PROGRAMMING<br />

extern int TakeProfit1 = 40;<br />

extern int TakeProfit2 = 80;<br />

extern int TakeProfit3 = 120;<br />

extern int MaxOrders = 3;<br />

Next, we will declare our arrays, calculate our stop loss and take profit, and load our calculated prices<br />

into the array:<br />

double BuyTakeProfit[3];<br />

double BuyStopLoss[3];<br />

BuyTakeProfit[0] = CalcBuyTakeProfit(Symbol(),TakeProfit1,Ask);<br />

BuyTakeProfit[1] = CalcBuyTakeProfit(Symbol(),TakeProfit2,Ask);<br />

BuyTakeProfit[2] = CalcBuyTakeProfit(Symbol(),TakeProfit3,Ask);<br />

BuyStopLoss[0] = CalcBuyStopLoss(Symbol(),StopLoss1,Ask);<br />

BuyStopLoss[1] = CalcBuyStopLoss(Symbol(),StopLoss2,Ask);<br />

BuyStopLoss[2] = CalcBuyStopLoss(Symbol(),StopLoss3,Ask);<br />

We start <strong>by</strong> declaring the arrays to hold the stop loss and take profit prices, BuyTakeProfit and<br />

BuyStopLoss. The number of array elements must be indicated when declaring the array. Array<br />

indexes start at zero, so <strong>by</strong> declaring an array dimension size of 3, our starting index is 0, and our<br />

largest index is 2.<br />

Next, we calculate the stop loss and take profit prices using the functions we defined in chapter 4 –<br />

CalcBuyStopLoss() and CalcBuyTakeProfit(). We assign the calculated stop loss or take profit<br />

value to the appropriate array element. Note that the first array index is 0 and the third array index is<br />

2.<br />

Here is the for loop for placing the orders:<br />

for(int Count = 0; Count

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!