Error 130 Assistance needed please.

 

I have slowly been trying to learn how to code in mq4 and have tentatively put this together, but I am gettin an error 130 . I can't for the life of me work out what is wrong. I have been running it on GBPJPY M15. Any input would be greatly appreciated.

extern double StopLoss = 0;
extern double TakeProfit = 20;
extern double Lots = 1;
extern double MagicNumber = 0;


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()  {
//----

if(Volume[0]>1) return;    
     //Create EMA variable
double EMAind0 = iMA(Symbol(),0,20,0,MODE_EMA,PRICE_CLOSE,0);
double EMAind1 = iMA(Symbol(),0,20,0,MODE_EMA,PRICE_CLOSE,1);
double EMAind2 = iMA(Symbol(),0,20,0,MODE_EMA,PRICE_CLOSE,2);
     //Test For Long Entry
     int Ticket;
     if (Open[0] > EMAind0 && High[1] > EMAind1 && Low[1] > EMAind1 && High[2] > EMAind2 && Low[2]<= EMAind2) 
     {
     Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 0, StopLoss, TakeProfit, "This is Driving Me mad!", 0, 0, DodgerBlue);
     return;
     }
           
      //Test For Short Entry

     if (Open[0] < EMAind0 && High[1] < EMAind1 && Low[1] < EMAind1 && High[2] < EMAind2 && Low[2]>= EMAind2) 
     {
     Ticket = OrderSend(Symbol(), OP_SELL, Lots, Ask, 0, StopLoss, TakeProfit, "This is Driving Me mad!", 0, 0, Red);
     return;
     }
            
//----
   return(0);
  }
Thank you.
 

Buy at Ask, Sell at Bid.


Stoploss and Takeprofit need to be prices (or 0), not "pips".

 

Micro - get used to always using magic number - read up in forum if not understand benefits of using

 

Great thanks, does this look better, It works better!!

nt Ticket;
     if (Open[0] > EMAind0 && High[1] > EMAind1 && Low[1] > EMAind1 && High[2] > EMAind2 && Low[2]<= EMAind2) 
     {
     Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 0, StopLoss,Ask + TakeProfit, "This is Driving Me mad!", MagicNumber, 0, DodgerBlue);
     return;
     }
           
      //Test For Short Entry
 
     if (Open[0] < EMAind0 && High[1] < EMAind1 && Low[1] < EMAind1 && High[2] < EMAind2 && Low[2]>= EMAind2) 
     {
     Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 0, StopLoss, Bid - TakeProfit, "This is Driving Me mad!", MagicNumber, 0, Red);
     return;
     }


Thanks again

 

presume TakeProfit is normalized to Symbol() ?

MagicNumber is (say for example: MagicNumber++, or whatever scheme devised of course :) each time use so have unique value for each order ?

(long as keep track of magic# of course - see some who favor >1 open trade at once - imho makes life/code more confusing and target for errors at runtime, can always run same EA with different magicNumber scheme on another chart or... still doing single order at a time idea)

just my ideas - I like to make simple, others make hard imho but think making simple... ah well, is big bad world and we all differ in view > thought > action :)

btw,

Nice to see real understandable variable names.

Some coders use say: sy/symbol, pr/price, op/TradeOpCode, pb/BidPrice, pa/AskPrice, ... (these seen recently in published/public code)

Is personal of course - my take is that IF any code reader needs directions or module header text to decide on what every variable name means THEN why bother reading?


like said, is personal opinion.


looks asif joining the 'dots' nicely... :o))

 

Thanks ukt.



What do you mean by normalizing TakeProfit to Symbol()?



I don't think I'd understand what was going on unless I used understandable variable names, I'm struggling as it is!!!



I've spent the day trying to work out how to add another rule to open trades. This time using AC and only opening if the AC is green for a long and red for a short. I'd be very grateful if you could point me in the right direction.



Re- magic numbers, would using the time of the trade be ok?



Thanks for the encouragement too.

 

Well, a few minutes after writing the last post, it may have slipped into place. Would I be right in putting this to take into account the AC?



double EMAind0 = iMA(Symbol(),0,20,0,MODE_EMA,PRICE_CLOSE,0);
double EMAind1 = iMA(Symbol(),0,20,0,MODE_EMA,PRICE_CLOSE,1);
double EMAind2 = iMA(Symbol(),0,20,0,MODE_EMA,PRICE_CLOSE,2);
     //Create the AC variable
double ACind = iAC(NULL, 0,0);
     //Test For Long Entry
     int Ticket;
     if (Open[0] > EMAind0 && High[1] > EMAind1 && Low[1] > EMAind1 && High[2] > EMAind2 && Low[2]<= EMAind2 && ACind > 0) 
     {
     Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 0, StopLoss,Ask + TakeProfit, "This is Driving Me mad!", MagicNumber, 0, DodgerBlue);
     return;
     }
           
      //Test For Short Entry
 
     if (Open[0] < EMAind0 && High[1] < EMAind1 && Low[1] < EMAind1 && High[2] < EMAind2 && Low[2]>= EMAind2 && ACind < 0)
 

Ok, Thats wrong. I only want to open long trades when the AC is green and short when they are red.



:0(

 
MicroDot:

Thanks ukt.


What do you mean by normalizing TakeProfit to Symbol()?

(1) I may have answered your question here: 'Error Order Send 138.'

in editor docs start here: MQL4 Reference - Conversion functions, and now click NormalizeDouble

Also see same but in online docs: MQL4 Reference -> Conversion functions -> NormalizeDouble

quick: if gbp/usd pair, price has 4 digits right of decimal point see (1), so you must ensure any other double values you use with Ask,Bid,Close[n],... have the same structure and this is where NormalizeDouble() comes into play. Most code found on site will use NormalizeDouble() so plenty of refs out there.


Normalization even creeps into double arithmetic, see editor docs: MQL4 Reference - Basics - Operations & Expressions - Operations of relation

wowee great fun... I'm learning here myself :)

I think by normalizing the outcome that any digits farther right then used by Symbol() will simply be chopped during normalize call: hence then is the time to compare normalized result with null/0/whatever! eg, if gbp/usd then 0.0000123 - 0.0000023 = 0.00001 and of course != 0. But if NormalizeDouble(0.00001,Digits) or even NormalizeDouble(0.00001,MarketInfo(Symbol(),MODE_DIGITS)) should get 0 and now 0==0... phew!

Anyway, I appreciated that doubles can be an issue but I've learned that gotta really be careful when messin with doubles all the time!

I don't think I'd understand what was going on unless I used understandable variable names, I'm struggling as it is!!!

me to - can never remember what's what and I do not mind typing longer names, trouble is... even then I get confused - go figure!

I've spent the day trying to work out how to add another rule to open trades. This time using AC and only opening if the AC is green for a long and red for a short. I'd be very grateful if you could point me in the right direction.

am going to beg off here - not use indicators often, other methods used at the moment but am sure with a bit of trial and error lightBulbs will turn on!

A very knowledgeable person on this forum (phy) has posted here: iAC & iAO Indicators - Counting Bars

see article sections "Acceleration/Deceleration (AC)" and "Awesome Oscillator (AO) by Bill Williams", plus others of course... in MQL4 Language for Newbies. Technical Indicators and Built-In Functions

Re- magic numbers, would using the time of the trade be ok?

seems to me that as long as 1)each order has unique magic# and 2)the EA remembers magic number(s) then no problem

but - many do just as you have done via

extern double MagicNumber = 0;

usually rather than zero, put a non zero number and then each time you run same EA on another chart, change the value via the Inputs Tab of the program properties window when the EA starts up.

Now, if say have 2 EAs running, each with their own MagicNumber - their orders will be identifiable by that EA alone - meaning no other EA can mess with them, yes?

Schemes are as many as programmers... eg, I segment the magic# 32bit int into 4 fields consisting of expertId,symbolId,periodId and order number id (in least significant 5digits which is just incremented each time place order). Overkill probably but is scheme I developed and suits me.

Again tho, like extern double MagicNumber I use extern int eiExpertId - just as long as each EA has some unique part to the magic# - that's the crucial bit imho.

Thanks for the encouragement too.

no problem..

 

As Point is a pre-defined variable, is it possible to multiply the TakeProfit by Point or is there a problem with that?

ie

Ask + TakeProfit * Point
  • or would I have to use
NormalizeDouble(Ask + TakeProfit * Point,MODE_DIGITS)

?


Micro

 

NormalizeDouble(Ask + TakeProfit * Point,MODE_DIGITS) -----> NormalizeDouble(Ask + TakeProfit * Point,Digits)

Look up MODE_DIGITS and MarketInfo() and NormalizeDouble() and pre-defined variables...

Learn to use the Print() function, MQL4 gives the coder all the tools to 'see' themselves what's what...

tbh, far better than posting all questions on forum. Why? one learns how to use MQL4 doing tests ;o)

all have to do to see how virtually all parts of MQL4 hang together is just get creative with the Print() function.

eg,

//Script File: test.mq4
//
#property show_inputs

extern double StopLoss = 0;
extern double TakeProfit = 20;
extern double Lots = 1;
extern double MagicNumber = 0;

int start()
{
Print("Symbol()=",Symbol(),", Ask=",Ask,", TakeProfit=",TakeProfit," Point=",Point
,", Ask + TakeProfit * Point = ",Ask + TakeProfit * Point);

//2008.04.14 22:06:02 test GBPUSD,Daily: Symbol()=GBPUSD, Ask=1.9784, TakeProfit=20 Point=0.0001
//, Ask + TakeProfit * Point = 1.9804

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

Print("Symbol()=",Symbol(),", Ask=",Ask,", TakeProfit=",TakeProfit," Point=",Point
,", NormalizeDouble(Ask + TakeProfit * Point,Digits) = ",NormalizeDouble(Ask + TakeProfit * Point,Digits));

//2008.04.14 22:06:02 test GBPUSD,Daily: Symbol()=GBPUSD, Ask=1.9784, TakeProfit=20 Point=0.0001
//, NormalizeDouble(Ask + TakeProfit * Point,Digits) = 1.9804

return(0);
}


it really is that simple! no limits what can do...