# Experts: Proper Bot - page 4

140

Excellent Patrick thanks!  I am getting similar backtest using 3 levels by this technique.  Works great.  I have an idea to make this thing more usable for different traders favorite indicators. But I'm not too good a coding yet.

In this section:

if(Bid<Low_Level)i_Signal=0;

if(Bid>High_Level)i_Signal=-1;

if(i_Signal==0) return(0);

It appears that the 0 means do not trade, 2 means open the first order and begin trading in the BUY direction, and -1 means open the first order and begin trading in the SELL direction.  The MA equations are deciding which code.

How difficult would it be to replace this section of code with a iCustom() block to pull indicator values from an indicator in the indicator folder, and then convert it to 0,2,-1?   I know each indicator would be different, requiring a different code to turn the data into a 0,2,-1 format, but I really just need to see it done so I can figure out how to do it with my own indicator.   Possible?

Mojo

140

Let me elaborate....

I have found the if-else-elseif statement in my favorite indicator that would be a handy place to define an int value of 0, 2, or -1.  So In that indicator, I would have to buffer that int so I could call it up from the ProperBot code.  Calling it up in the ProperBot code would go in place of the code I listed in my last message.  I KNOW this can be done.  I just can't get the syntax right.....

140

OK----Here is my attempt.  It seems to be working, but I don't think the 0,2,-1 code is updating on each tick.   Here is my silly indicator, followed by the code I changed in Proper....Te indicator draws a line at Open, Close, and the average of open and close.  Then the Code I put into Proper pulls the buffer values of candle#2 and candle#10 and compares them.  The result decides weather we are a buy or a sell.   It looks like it works, BUT, I don't think the result updates through time.  I run a backtest, and if the first result is sell, then it goes 100% sell.  If the first result is buy, then the whole run is 100% buy.  So something isn't right....Any help?

//--------------------------------------------------------------------

// userindicator.mq4

// The code should be used for educational purpose only.

//--------------------------------------------------------------------

#property indicator_chart_window    // Indicator is drawn in the main window

#property indicator_buffers 3       // Number of buffers

#property indicator_color1 Blue     // Color of the 1st line

#property indicator_color2 Red      // Color of the 2nd line

#property indicator_color3 Yellow   // Color of the 3rd line

double Buf_0[],Buf_1[],Buf_2[];     // Declaring arrays (for indicator buffers)

//--------------------------------------------------------------------

int init()                          // Special function init()

{

SetIndexBuffer(0,Buf_0);         // Assigning an array to a buffer

SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2);// Line style

SetIndexBuffer(1,Buf_1);         // Assigning an array to a buffer

SetIndexStyle (1,DRAW_LINE,STYLE_DOT,1);// Line style

SetIndexBuffer(2,Buf_2);         // Assigning an array to a buffer

SetIndexStyle (2,DRAW_LINE,STYLE_SOLID,1);// Line style

return;                          // Exit the special funct. init()

}

//--------------------------------------------------------------------

int start()                         // Special function start()

{

int i,                           // Bar index

Counted_bars;                // Number of counted bars

//--------------------------------------------------------------------

Counted_bars=IndicatorCounted(); // Number of counted bars

i=Bars-Counted_bars-1;           // Index of the first uncounted

while(i>=0)                      // Loop for uncounted bars

{

Buf_0[i]=Open[i];             // Value of 0 buffer on i bar

Buf_1[i]=Close[i];            // Value of 1st buffer on i bar

Buf_2[i]=(Open[i]+Close[i])/2;    // Value of 2nd buffer on i bar

i--;                          // Calculating index of the next bar

}

//--------------------------------------------------------------------

return;                          // Exit the special funct. start()

}

//--------------------------------------------------------------------

Here is what I did to the code in Proper:

//if(Ask>High_Level)i_Signal=0;    //   No signal due to price externs  .... Commented out by MJM

//if(Bid<Low_Level)i_Signal=0;     //   No signal due to price externs.... Commented out by MJM

//if(Bid>High_Level)i_Signal=-1;   //   Signal set <0  SELL SIGNAL.... Commented out by MJM

//if(i_Signal==0) return(0); // no signal, wait for the next tick.... Commented out by MJM

double val_from_indicatorbar2=iCustom(NULL,30,"simple-indicator",0,2,0);

double val_from_indicatorbar10=iCustom(NULL,30,"simple-indicator",1,10,0);

if(val_from_indicatorbar2<val_from_indicatorbar10)i_Signal=2;

if(val_from_indicatorbar2>val_from_indicatorbar10)i_Signal=-1;

if(val_from_indicatorbar2==val_from_indicatorbar10)i_Signal=0;

if(i_Signal==0) return(0); // no signal, wait for the next tick

2201

Are the Do not buy above this level and Do not sell below this level set correct for the pair you are testing?
140

Oh yes.  I have those set to be completely unobstructed. 3.0000 and 0.00001.

140

HAHA! I got it!  Here is what I did under the Get a Signal section using iCustom(): (My custom indicator is called MOJO....it is a trend finder....now the buy or sell switch is decided by getting the results of my separate MOJO indicator. AND IT  IS KILLING the backtest. Thatnk you so much for making the Proper Bot!!!!  My next task is to craft a block that will close all open orders if the trend switches........

//if(Ask>High_Level)i_Signal=0;    // here.  No signal due to price externs  .... Commented out by MJM

//if(Bid<Low_Level)i_Signal=0;     // or here.  No signal due to price externs.... Commented out by MJM

//if(Ask<Low_Level)i_Signal=2;     // or here. Signal set >0  BUY SIGNAL.... Commented out by MJM

//if(Bid>High_Level)i_Signal=-1;   // or here. Signal set <0  SELL SIGNAL.... Commented out by MJM

//if(i_Signal==0) return(0); // no signal, wait for the next tick.... Commented out by MJM

//-------------------------------------------

//----MJM CODE TO GET SIGNAL FROM MOJO-------

//-------------------------------------------

double uptrend_from_MOJO_MJM=iCustom(NULL,30,"#MOJO-Averages-MJM",0,0); //This is the SetIndexBuffer(0, mojo_uptrend);  // This buffer is the MOJO Uptrend Line (blue)

double downtrend_from_MOJO_MJM=iCustom(NULL,30,"#MOJO-Averages-MJM",1,0); //This is the SetIndexBuffer(1, mojo_dntrend);  // This buffer is the MOJO Downtrend Line (red)

if (uptrend_from_MOJO_MJM>0)i_Signal=2;

if (downtrend_from_MOJO_MJM>0)i_Signal=-1;

if (i_Signal==0) return(0); // no signal, wait for the next tick....

//-------------------------------------------

//--END MJM CODE TO GET SIGNAL FROM MOJO-----

//-------------------------------------------

140

Oooh, Patrick, slight problem.  I need closes to happen FIFO for the United States...Any chance you would know how to make that work?

140

Alos, it appears the closure is happening independent of the T/P setting.  I can't figure out what it is doing from the code. Maybe you can explain?

I did one run with T/P set to 30 pips. and on set to 40 pips. Then I compared a specific basket of trades.  The "modify order" to set the T/P and S/L seems to be following the setting

 1st Run Short Price S/L T/P T/P 1.06459 1.07659 1.06059 -0.004 1.06577 1.07777 1.06177 -0.004 1.06696 1.07896 1.06296 -0.004 Looks good..... 2nd Run 1.06459 1.07659 1.06159 -0.003 1.06577 1.07777 1.06277 -0.003 1.06696 1.07896 1.06396 -0.003 Looks good....but then: 1st Run closed at 1.06558 2nd Run closed at 1.06558

Something perhaps isn't right?

2201

Perhaps set the trailing loss at a value greater than the Take Profit
371

I am using a VPS for the EA. But i notice that when I am monitoring the trades on my PC the EA places double trades. When i close the PC..it places one trade as it should. What could be the problem?