Download MetaTrader 5
To add comments, please log in or register
Are you a good trader? Become a signals provider and make even more money!
shyftus
195
shyftus 2016.06.20 02:46 

Hi trying to transition to actual coding from modular interface - have managed to code long side OK, but have made a mistake somewhere with the sell function ... can anyone spot? Imagine it's a pretty simple/obvious mistake. I'm not getting any order send errors. Cheers.

#define __STRATEGY_MAGIC 1273244552

//Inputs

//Declaration

///Price

double _PreLow;
double _PreLow2;
double _PreLow3;
double _PreHi;
double _PreHi2;
double _PreHi3;
double _COpen;

///Market
double _CVolume;
double _Spread;

///Math
double _TProfBuy;
double _TProfBuyB;
double _TProfBuyN;

double _TProfSell;
double _TProfSellB;

///Common
bool _VolCheck;

///Buy Logic
bool _FraCheckBuyA;
bool _FraCheckBuyB;
bool _Buy;

///Sell Logic
bool _FraCheckSellA;
bool _FraCheckSellB;
bool _Sell;


///Trade
bool _Open_Buy;
bool _Open_Sell;

int start(){

   //Price
   _PreLow = iLow(Symbol(),0,1);
   _PreLow2 = iLow(Symbol(),0,2);
   _PreLow3 = iLow(Symbol(),0,3);
   _PreHi = iHigh (Symbol(),0,1);
   _PreHi2 = iHigh (Symbol(),0,2);
   _PreHi3 = iHigh (Symbol(),0,3);
   _COpen = iOpen (Symbol(),0,0);
   
   //Market
   _CVolume = iVolume(Symbol(),0,0);
   _Spread = MarketInfo(Symbol(),MODE_SPREAD)/ 100000;
   
   //Math
   
   _TProfBuy = _COpen - _PreLow2;
   _TProfBuyB = _TProfBuy + _Spread;
   _TProfBuyN = _TProfBuyB * 100000;
   
   _TProfSell = _PreHi2 - _COpen;
   _TProfSellB = _COpen - _TProfSell;
   
   //Common
   _VolCheck = _CVolume == 1;

   //Buy Logic
   _FraCheckBuyA = _PreLow > _PreLow2;
   _FraCheckBuyB = _PreLow3 > _PreLow2;
   _Buy = _FraCheckBuyA && _FraCheckBuyB && _VolCheck;
   
   //Sell Logic
   _FraCheckSellA = _PreHi < _PreHi2;
   _FraCheckSellB = _PreHi3 < _PreHi2;
   _Sell = _FraCheckSellA && _FraCheckSellB && _VolCheck;

   //Buy
   if(_Buy &&  !__isExist(0))_Open_Buy = OrderSend(Symbol(),0,.1,MarketInfo(Symbol(),MODE_ASK),0,_PreLow2,MarketInfo(Symbol(),MODE_ASK)+MarketInfo(Symbol(),MODE_POINT)*_TProfBuyN,"",__STRATEGY_MAGIC + 0)>=0;
   return(0);
   
   //Sell
   if(_Sell &&  !__isExist(1))_Open_Sell = OrderSend(Symbol(),1,.1,MarketInfo(Symbol(),MODE_BID),0,_PreHi2,MarketInfo(Symbol(),MODE_BID)-MarketInfo(Symbol(),MODE_POINT)*_TProfSellB,"",__STRATEGY_MAGIC + 1)>=0;
   return(0);
}

//Services
bool __selectOrderByMagic(int __magic){for(int __i=0;__i<OrdersTotal();__i++){if(OrderSelect(__i,SELECT_BY_POS,MODE_TRADES)&&OrderMagicNumber()==__STRATEGY_MAGIC+__magic)return(true);}return(false);}
bool __isExist(int __magic){return(__selectOrderByMagic(__magic));}
whroeder1
13596
whroeder1 2016.06.20 12:42  
shyftus: I'm not getting any order send errors. Cheers.
  1. You don't get any errors because you don't check them. Check your return codes and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. What is the line below your first OrderSend?
  3. Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling (or moving my eyes) back and forth trying to read it. Edit the post with formatted code and you might get additional help.
alexquan
7
alexquan 2016.06.20 13:21  

 change it for something like this

 if (a>c) //condition

   {

     Open_Buy = OrderSend(Symbol(),0,.1,MarketInfo(Symbol(),MODE_ASK),0,_PreLow2,MarketInfo(Symbol(),MODE_ASK)+MarketInfo(Symbol(),MODE_POINT)*_TProfBuyN,"",__STRATEGY_MAGIC + 0);

  } 

if  doesnt need a return()....return() is use for functions

.....this is how my own EA looks like and is working..

 dont forget to  declare your variable...at the beggining of your code

double a; 

int Ticketbuy;

int  Ticketsell; 

if(a > 16383.5)     // this condition is part of a random trading algorith

      {

       // Buy

      Ticketbuy=OrderSend(Symbol(),OP_BUY,lotesize,Ask,100,NULL,NULL,NULL,0,0,Blue);

        } 

 else

      {

       // Sell

       Ticketsell= OrderSend(Symbol(),OP_SELL,lotesize,Bid,100,NULL,NULL,NULL,0,0,Red);

       }

this is without a stoploss and takeprofit.....if you what to add stoploss and takeprofit you have to check the stoploss value to see if its bigger  or equal to the  min value . 

unless you are willing to put alot, and i mean alot of hours of work into this, is better to buy one. i have ea of more than 800 lines an still not in profit. 

shyftus
195
shyftus 2016.06.21 04:12  
WHRoeder:
  1. You don't get any errors because you don't check them. Check your return codes and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. What is the line below your first OrderSend?
  3. Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling (or moving my eyes) back and forth trying to read it. Edit the post with formatted code and you might get additional help.

Thanks - worked it out after a break from screen. When duplicating, modifying the buy code I duplicated the return function.

Alex - if you have 800 lines and still no profit you're starting without an edge - I try to find a price edge before using indicators to weed out losers (and winners) - ie a signal that yields positive win rate/return/profit from the outset. Starting with anything else is like polishing a turd.

/
To add comments, please log in or register