PLEASE SOMEONE HELP ME FIX THIS CODE.PLEASE!!!

 

Hello All,

I hope all is well with everyone and the recent volatility in the forex and stock has been favorable to you all.I have not been too lucky but I don't intend to to give up.

I need help with an EA am trying to develop.it is a very smal program involving displaced moving averages. unfortunately I am struggling in programming hence I would be imensely grateful if some one can help me look at the code below and fix it for me.Its an ida I have I hope to test demotrade ans see the output ..

As can been seen in the code below(I hope it is clear enough).the idea is based on using a displaced simple moving average with a period of 5 and positive shift of 2.

for buy signals, the the difference between the dma value and the closing price of the security should be less than or equl toa certain number(for now I am experimenting with 22) and for sell signal, the diference ahould be greater than or equal that number.the maximum number open position should not exceed one.this should be part of the criteria for opening a postion.

An open buy trade should be closed when conditions for a sell trade(as mention above) exists conversely,a sell tposition should be closed when conditions for buy trade exists

I have difficulty in writting the following codes snipet for the EA:

1) code for verifying that an opnem position exist

2)code for closing an open postion

3)code for opening a positons when the conditions are met.

I will be very greatfull if someone can help me lok at the code below and fix help me out of this difficulty that is giving me sleepless nite and worry.I really need help.

Looking forward to getting help frpom any kind heatted person out there.

cheers,

malachy

//+------------------------------------------------------------------+
//| DMA
//| Copyright © 2008, malachy
//|
//+------------------------------------------------------------------+


extern double Lots = 0.1;

e
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double ma_val; // value of displaced moving simple moving average

int total; // max order
int ticket;

ma_val=iMA( NULL,0,5,2,0,0,0)

total=OrdersTotal();

if (total >= 1 && ma_value - PRICE_CLOSE >= +22)

{
OrderClose(order_id,1,Ask,5,Red);
return(0);
} //close buy trade

if (total >= 1 && ma_value - PRICE_CLOSE <= -22)

{
OrderClose(order_id,1,Bid,5,Red);
return(0);

}

//close sell trade

if (total <= 0 && ma_value - PRICE_CLOSE <= -22) // check for long possibility
{
OrderSend( string symbol, OP_BUY,1,Ask, 5,0,0,NULL, 9055500, 0,Green)
}

// buy!
if (total >= 0 && ma_value - PRICE_CLOSE >= +22) // check for short possibility

{
ticket=OrderSend( string symbol, OP_SELL, 1, Bid, 5,0,0,NULL, 9103525,0,Green)
}

//sell!

return(0);
}
// the end.

 

oh....that' something serious to coop with: But looking at the date of it I think our chance to fix it has gone...if not...just post it again and we can have some closer chat about it.

But I got a problem or a question here:

Overbought[i]=(iCustom(NULL,0,"AMASTL",AMA_Fast,AMA_Slow,AMA_Range,AMA_Filter,Bars-1,0,i+1)*AMA_Weight+iCustom(NULL,0,"AMASTL",SAMA_Fast,SAMA_Slow,SAMA_Range,SAMA_Weight,Bars-1,0,i+1)*SAMA_Weight)
                     /
                     (SAMA_Weight+AMA_Weight)
                     +
                     if(VHF_Acceleration==true)
                        {
                        if(Normal_Acceleration==false)
                           { 
                           iATR(NULL,0,ATR_Period,i+ATR_Shift)*(iCustom(NULL,0,"VHF",VHF_Period,0,i+VHF_Shift)*10*VHF_Accelerator);
                           }
                                   
                        else
                           {
                            iATR(NULL,0,ATR_Period,i+ATR_Shift)
                           *
                           (((iCustom(NULL,0,"VHF",VHF_Period,0,i+VHF_Shift)*10*VHF_Accelerator)
                           +
                           Acceleration)/2);
                           }
                        }
                     else
                        {
                        if(Normal_Acceleration==false)
                           {
                           iATR(NULL,0,ATR_Period,i+ATR_Shift);
                           }
                        else
                           {
                           iATR(NULL,0,ATR_Period,i+ATR_Shift)*Acceleration;
                           }
                     }

It keeps telling me the following when I compile it:


If-Function Errors

What have I done Wrong? Just need a basic explanation...I hope I can figure it out as much by myself as I can. Is it really too complex or have I just forgotten a semicolon somewhere?

Would be great if this topic didn't die before I got the answer *cheeky* :D

 

You can't put a if condition inside of an assignment line. You have a if statement following a "+".

.

P.S.: As I was typing this, I was finishing my sentences with a semi-colon (;) instead of a period lol.

 
MMMhhh, thanks, that was something I didn't know. I will try to do something different then.
 
ErrorProgrammer:
MMMhhh, thanks, that was something I didn't know. I will try to do something different then.


BTW: This dose what you wanted (I think) (remeber: true == 1, false == 0):

Overbought[i] = 
            (iCustom(NULL,0,"AMASTL",AMA_Fast,AMA_Slow,AMA_Range,AMA_Filter,Bars-1,0,i+1)*AMA_Weight 
                 + iCustom(NULL,0,"AMASTL",SAMA_Fast,SAMA_Slow,SAMA_Range,SAMA_Weight,Bars-1,0,i+1)*SAMA_Weight)
            /(SAMA_Weight+AMA_Weight)
     		
            + (VHF_Acceleration==true)*(
                  (Normal_Acceleration==false)*(
                        iATR(NULL,0,ATR_Period,i+ATR_Shift)*(iCustom(NULL,0,"VHF",VHF_Period,0,i+VHF_Shift)*10*VHF_Accelerator)
                  )
                  + (Normal_Acceleration==true)*(
                        iATR(NULL,0,ATR_Period,i+ATR_Shift)
                        *(((iCustom(NULL,0,"VHF",VHF_Period,0,i+VHF_Shift)*10*VHF_Accelerator) + Acceleration)/2)
                  )
            ) 
            + (VHF_Acceleration==false)*(
                  (Normal_Acceleration==false)*(
                        iATR(NULL,0,ATR_Period,i+ATR_Shift)
                  )
                  + (Normal_Acceleration==true)*(
                        iATR(NULL,0,ATR_Period,i+ATR_Shift)*Acceleration
                  )
            );


But it is definitely NOT a recomended coding style... (Remids me a little of Lisp...)


/LV

 
That's an interesting one....I solved the problem already by inserting two more buffers but I'll have to take this one into consideration for more complex problems...thanks LastViking!
 

+ (VHF_Acceleration==true)

would be equivalent to

+ 1 or + 0

depending on if the comparison is true or false.

.

Remember that a "==" will always return 1 or 0. I've honestly never seen anyone write a condition inside of a calculation like this. Just put what you want in a condition outside and use that variable with the result inside the calculation. The only thing that could be done that would be good programming would be to use the (a == b ? c : d) conditional, but MQL4 doesn't support it.

Jon

 

Yes, but the problem is that the values normally depend on i...and for something that depends on a variable you need to create an Array to save the certain values of an Indi etc for each bar. and as far as my understanding is, each array associated with a for(...)-function needs a buffer. and you can just have a maximum of 8 buffers.

Am I right or Have I got the bits with the Array wrong?

 

An indicator can have 8 external buffers (0-7). This is where you store the indicator values that will appear on the chart window and this is also what will be fetched from an EA. Other than that I'm not fully sure what you were asking.

.

Jon

 
So basically, you can have as many arrays in an Indi as you want, but can only have 8 lines drawn...am I right....?
 

Yeah, in any program you can have as many arrays as you want but what I'm talking about are the external buffers for MT4 to draw lines and transfer info to EA's etc.. The external buffers just happen to be arrays as well so you use them the same way. The only difference is that MT4 will make them accessible from outside and use them to draw lines.

.

Jon

Reason: