I need help in assigning functions as variable values

 

I just started learning MQL4 last year, I wish writing something like;

double floatingbalance;

double lotsize

floatingbalance=double AccountEquity()

lotsize=floatingbalance*0.001

I hope this makes sense:) The above is to calculate the lot size using the account information function

Please can anybody help me out?

 

You have already declared floatingbalance as double: double floatingbalance;

Then use:

floatingbalance = AccountEquity();

 
DayTrader:

You have already declared floatingbalance as double: double floatingbalance;

Then use:

floatingbalance = AccountEquity();

Thanks Day trader, I still need more help on this funtion

lotsize=floatingbalance*0.001

The idea is to insert the variable in the ordersend function this way


int OrderSend("NULL",4,lotsize,Ask,3,Ask-40*point, Ask+40*point,"buy stop",0,0,Green);


Thanks once again

 
lotsize=NormalizeDouble(floatingbalance*0.001,1);
 
Roger:
lotsize=NormalizeDouble(floatingbalance*0.001,1);

I'm Glad I joined this forum, I think I should share the full idea behind the EA I wish to code and show how far I've gone

The system is based on the first candle of the day, The first Hour 1 candle that forms will be split horizontally into two to

determine point x.

A buy stop 40pips away from point x and a sell stop 40 pips away from point x

the take profit of the buy stop should be 40 pips away from the entry point the stop loss will be 120pips away from the entry point

the take profit of the sell stop should be 40 pips away from the entry point the stop loss will be 120pips away from the entry point

if price reaches stop loss or take profit all existing pending orders should be closed and the first candle for the following day will be the next point x

if both buy stop and sell stop are not triggered till the following day and another first candle of the day appears, all pending order should be

deleted and the point x for the present day determined by the new first candle of the newest day

 
Can anyone code the above strategy for me please, I've tried some functions please see below;


To determine the Point X where the pending orders will be determined I did the following,

double Xcandle;

double PoinX

datetime CY //To determine Current Year

datetime CM //To determine Current Month

datetime CD //To determine Current Day

datetime CH //To determine Current Hour


Xcandle=iBarShift("NULL",0,D'CY.CM.CD.CH',exact=True);

//The above code is to find the Xcandle


Xcandle body=iOpen("NULL",0,Xcandle)-iClose("NULL",0,Xcandle)

candlesplit= mathAbs(Xcandlebody)

PointX=candlesplit/2;

//The above code is to split the Xcandle into two

Unfortunately the value ithink will be returned cannot be used for entering trades

since it will not be a market price it may probablybe something like 0.0006

 
0808 wrote >>

To determine the Point X where the pending orders will be determined I did the following,

double Xcandle;

double PoinX

datetime CY //To determine Current Year

datetime CM //To determine Current Month

datetime CD //To determine Current Day

datetime CH //To determine Current Hour

Xcandle=iBarShift("NULL",0,D'CY.CM.CD.CH',exact=True);

//The above code is to find the Xcandle

Xcandle body=iOpen("NULL",0,Xcandle)-iClose("NULL",0,Xcandle)

candlesplit= mathAbs(Xcandlebody)

PointX=candlesplit/2;

//The above code is to split the Xcandle into two

Unfortunately the value ithink will be returned cannot be used for entering trades

since it will not be a market price it may probablybe something like 0.0006

if (TimeHour(TimeCurrent())==1 && TimeMinute(TimeCurrent())==0)
{
double x = NormalizeDouble((iHigh(Symbol(),PERIOD_H1,1)+iLow(Symbol(),PERIOD_H1,1))/2.0,Digits);
OrderSend(Symbol(),OP_BUYSTOP,Lots,x+Step*Point,3,x+(Step-SL)*Point,Ask+(Step+TP)*Point,"",0,0,Green);
OrderSend(Symbol(),OP_SELLSTOP,Lots,x-Step*Point,3,x+(-Step+SL)*Point,Bid-(Step+TP)*Point,"",0,0,Red);
}

where Step=40, TP=40, SL=120

 
Please correct me if I'm wrong the above code will determine the first candle of the day with the if statement above double x floating point number will be the result of the first candle after being split into two the ordersend funtions will set the pending orders Right? If I'm right then I think the next stage should be a code which will delete the orders if both buy stop and sell stop were not triggered throughout the entire day and a new day comes a new first candle of the day forms How can the pending orders get deleted and the new first candle cause the program to loop back to the code above Thanks in advance
 
0808 wrote >>
Please correct me if I'm wrong the above code will determine the first candle of the day with the if statement above double x floating point number will be the result of the first candle after being split into two the ordersend funtions will set the pending orders Right? If I'm right then I think the next stage should be a code which will delete the orders if both buy stop and sell stop were not triggered throughout the entire day and a new day comes a new first candle of the day forms How can the pending orders get deleted and the new first candle cause the program to loop back to the code above Thanks in advance

the code assumes that the first candle of the day is at 0Hrs, and the computation of this 0Hr can only be done when the Hr is at 1Hr; so essentially at 0100Hrs, you look back at the 0Hr to do your computation; to get rid of pending orders the next day, use expiration time ie

int OrderSend(

string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)

so it will be something like this by placing a 24 hours expiration time

if (TimeHour(TimeCurrent())==1 && TimeMinute(TimeCurrent())==0)
{

datetime expiretime = TimeCurrent()+24*60*60;
double x = NormalizeDouble((iHigh(Symbol(),PERIOD_H1,1)+iLow(Symbol(),PERIOD_H1,1))/2.0,Digits);
OrderSend(Symbol(),OP_BUYSTOP,Lots,x+Step*Point,3,x+(Step-SL)*Point,Ask+(Step+TP)*Point,"",0,expiretime,Green);
OrderSend(Symbol(),OP_SELLSTOP,Lots,x-Step*Point,3,x+(-Step+SL)*Point,Bid-(Step+TP)*Point,"",0,expiretime,Red);
}

 
ronaldosim:

the code assumes that the first candle of the day is at 0Hrs, and the computation of this 0Hr can only be done when the Hr is at 1Hr; so essentially at 0100Hrs, you look back at the 0Hr to do your computation; to get rid of pending orders the next day, use expiration time ie

int OrderSend(

string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)

so it will be something like this by placing a 24 hours expiration time

if (TimeHour(TimeCurrent())==1 && TimeMinute(TimeCurrent())==0)
{

datetime expiretime = TimeCurrent()+24*60*60;
double x = NormalizeDouble((iHigh(Symbol(),PERIOD_H1,1)+iLow(Symbol(),PERIOD_H1,1))/2.0,Digits);
OrderSend(Symbol(),OP_BUYSTOP,Lots,x+Step*Point,3,x+(Step-SL)*Point,Ask+(Step+TP)*Point,"",0,expiretime,Green);
OrderSend(Symbol(),OP_SELLSTOP,Lots,x-Step*Point,3,x+(-Step+SL)*Point,Bid-(Step+TP)*Point,"",0,expiretime,Red);
}

Thanks so much,

I was thinking about another approach either to add to the trading technique or used for a different program entirely;

if the straddle hits the take profit zone which is automatically the stop loss of the second pending order,

then the point of take profit can be another level to determine point x and a new straddle is set where all existing pending orders are automatically deleted.

something like...

RefreshRates()

if(x+(Step-SL)*Point)==Ask()//If stoploss is equal to current ask price delete all existing pending orders

bool OrderDelete(int Ticket,Color color=CLR_NONE)

if(x+(Step-SL)*Point)==Bid()//If stoploss is equal to current bid price delete all existing pending orders

bool OrderDelete(int Ticket,Color color=CLR_NONE)


if(Ask+(Step+TP)*Point)==Ask()//If takeprofit is equal to current ask price delete all existing pending orders

bool OrderDelete(int Ticket,Color color=CLR_NONE)

if(Ask+(Step+TP)*Point)==Bid()If takeprofit is equal to current bid price delete all existing pending orders

bool OrderDelete(int Ticket,Color color=CLR_NONE)


The problem is knowing the ticket number, I hope I got the idea with the kind of codes I added

 
0808 wrote >>

Thanks so much,

I was thinking about another approach either to add to the trading technique or used for a different program entirely;

if the straddle hits the take profit zone which is automatically the stop loss of the second pending order,

then the point of take profit can be another level to determine point x and a new straddle is set where all existing pending orders are automatically deleted.

something like...

RefreshRates()

if(x+(Step-SL)*Point)==Ask()//If stoploss is equal to current ask price delete all existing pending orders

bool OrderDelete(int Ticket,Color color=CLR_NONE)

if(x+(Step-SL)*Point)==Bid()//If stoploss is equal to current bid price delete all existing pending orders

bool OrderDelete(int Ticket,Color color=CLR_NONE)

if(Ask+(Step+TP)*Point)==Ask()//If takeprofit is equal to current ask price delete all existing pending orders

bool OrderDelete(int Ticket,Color color=CLR_NONE)

if(Ask+(Step+TP)*Point)==Bid()If takeprofit is equal to current bid price delete all existing pending orders

bool OrderDelete(int Ticket,Color color=CLR_NONE)

The problem is knowing the ticket number, I hope I got the idea with the kind of codes I added

ok, I got it now; u shld add to the trading technique, and not have a different program. One question though - when will your straddle ends cos u start a new one every new day, so when will the prev day straddle ends?

found an error in prev code: the takeprofit shld be using the value x and not Ask or Bid

if (TimeHour(TimeCurrent())==1 && TimeMinute(TimeCurrent())==0)
{
double x = NormalizeDouble((iHigh(Symbol(),PERIOD_H1,1)+iLow(Symbol(),PERIOD_H1,1))/2.0,Digits);
OrderSend(Symbol(),OP_BUYSTOP,Lots,x+Step*Point,3,x+(Step-SL)*Point,x+(Step+TP)*Point,"",0,0,Green);
OrderSend(Symbol(),OP_SELLSTOP,Lots,x-Step*Point,3,x+(-Step+SL)*Point,x-(Step+TP)*Point,"",0,0,Red);
}

Reason: