How to code? - page 135

 

Error by comiling

Hi all

I have following error:

'<'-different types in comparsion

I try to modified follow line:

(NonLagMA_2D_S2&&D_S2Switch==1)

to

(Price_NowD_S2&&D_S2Switch==1)

Where's the problem?

Sorry can't upload the mql-file. It's no my script

 
:: you compare something with different types, so it has to be integers with integers, doubles with doubles, strings with strings... like this...

IN10TION

Badguy:
Hi all

I have following error:

'<'-different types in comparsion

I try to modified follow line:

(NonLagMA_2D_S2&&D_S2Switch==1)

to

(Price_NowD_S2&&D_S2Switch==1)

Where's the problem?

Sorry can't upload the mql-file. It's no my script
 

Closing Multiple Position By Magic Number - Help

hello all.

I'm new in mt4 programming and below are my very first EA. The purpose of this EA is to close all position regardless any currency pair based on the same magic number.

Let say under magic # 8675310, i got 2 position EURUSD & USDCFh. It shall be able to close all these pair when it reaches certain profit target.

The problem with this EA is,

Open Transaction # 1 EURUSD (able to close)

Open Transaction # 2 USDCFh (won't be able to close)

IT WON'T BE ABLE TO CLOSE TRANSACTION # 2.

Any Ideas ?

Thanks

//+------------------------------------------------------------------+

//| Closing_Trade_By_Magic_No_v1 .mq4 |

//| Mine |

//| Forex Trading Software: Forex Trading Platform MetaTrader 4 |

//+------------------------------------------------------------------+

#property copyright "Mine"

#property link "http://www.metaquotes.net"

//---- input parameters

extern int MagicNumber1=8675310;

extern int Profit1=10;

extern int MagicNumber2=8675311;

extern int Profit2=15;

extern int MagicNumber3=8675312;

extern int Profit3=15;

extern int MagicNumber4=8675313;

extern int Profit4=15;

extern int MagicNumber5=8675314;

extern int Profit5=15;

extern int MagicNumber6=0;

extern int Profit6=10;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

onScreenComment(98,"Tengak Initialize..");

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

string myMessage="";

myMessage = myMessage + ProfitLossMonitor(1,MagicNumber1,Pr ofit1,myMessage);

myMessage = myMessage + ProfitLossMonitor(2,MagicNumber2,Pr ofit2,myMessage);

myMessage = myMessage + ProfitLossMonitor(3,MagicNumber3,Pr ofit3,myMessage);

myMessage = myMessage + ProfitLossMonitor(4,MagicNumber4,Pr ofit4,myMessage);

myMessage = myMessage + ProfitLossMonitor(5,MagicNumber5,Pr ofit5,myMessage);

myMessage = myMessage + ProfitLossMonitor(6,MagicNumber6,Pr ofit6,myMessage);

onScreenComment(98,myMessage);

//----

//----

return(0);

}

string ProfitLossMonitor(int myGroupNumber,int myMagicNumber, int myProfit,string myMessage )

{

int total = OrdersTotal();

double MyCurrentProfit=0;

string MyOrderNo="";

for (int cnt = 0 ; cnt < total ; cnt++)

{

OrderSelect(cnt,SELECT_BY_POS,MODE_ TRADES);

if (OrderMagicNumber() == myMagicNumber)

{

MyCurrentProfit += OrderProfit();

MyOrderNo= MyOrderNo + "," + OrderTicket();

}

}

if(MyCurrentProfit>=myProfit)

CloseAll(myMagicNumber);

myMessage="Group Position #" + myGroupNumber + " " + myMagicNumber + "=" + myProfit + "(" + DoubleToStr(MyCurrentProfit,2) + " " + MyOrderNo + ")" + "\n" ;

return (myMessage);

}

void CloseAll(int myMagicNumber)

{

int total = OrdersTotal();

for (int cnt = 0 ; cnt < total ; cnt++)

{

OrderSelect(cnt,SELECT_BY_POS,MODE_ TRADES);

if (OrderMagicNumber() == myMagicNumber)

if(OrderType()==OP_BUY)

OrderClose(OrderTicket(),OrderLots( ),Bid,5,Violet);

if(OrderType()==OP_SELL)

OrderClose(OrderTicket(),OrderLots( ),Ask,5,Violet);

}

}

void onScreenComment(int myEvent, string myComment)

{

switch (myEvent)

{

case 98: Comment(myComment); break;

}

}

//+------------------------------------------------------------------+

Edit/Delete Message

 
The problem with this EA is,

Open Transaction # 1 EURUSD (able to close)

Open Transaction # 2 USDCFh (won't be able to close)

IT WON'T BE ABLE TO CLOSE TRANSACTION # 2.

Any Ideas ?

I assume that you are running the ea on the EURUSD chart at the time you try to close orders. as those positions are closing ok. When your code trys to close the USDCHF(a little dislexies?) positions its using the wrong bid and or ask, the closing price it uses is from the currency pair that the ea is attached too not the price of the possitions symbol. If your trying to close another currency pair from a chart that doesnot match that currency, you must first retrive the correct price before trying to close it.

keit

edit: Also the currency, USDCHF in this case must be displayed in your market watch window at the time your trying to retreive the correct quotes to close the orders. If the USDCHF is not listed in the market watch window you will not be able to get any quotes for that pair.

 

Thanks cockeyedcowboy !.

"you must first retrive the correct price before trying to close it".

Could your share the syntax or function that can do the above needs;

 

how to not trade till the next bar

I've tried programming for the first time, but have one issue.

- if I close a trade in a bar, I can only open a new trade when the new bar opens.

I have tried the following;

datetime time0=0;

int start()

if (time0 == Time[0]) return;

{

"program code"

}

time0 = Time[0];

return(0);

If I take this bit out I get multiple entries in various bar. With it in, I get far fewer entries (from 70 in a backtest. to 4), but with missing entries.

Anyone know what I'm doing wrong.

Thanks in advance.

 

You can use the NewBar() function below..

Like if(NewBar(){ ........programming here

bool NewBar() {

static datetime LastTime = 0;

if (Time[0] != LastTime) {

LastTime = Time[0];

return (true);

} else

return (false);

}

You might also want to test for open orders if you only want one order at a time.

Hope that helps.

Lux

 

Lux

Thanks for your help with this.

I think I've figured out what was going on on the program.

I was previously checking for a new bar at the start, so the program just checked the first tick of the new bar to see if it agreed with my signals, without checking the other ticks. This is why do few trade signals came through the backtest.

I have now placed the code correctly, (ie. where my ordersend instuction is) it seems to be working ok.

Am I correct in my thinking?

 

Please help to update the code of expert.

There is a simple expert. Code is clear and simple too, but i have a big problem - expert got only ONE try to Open/Close order.

Can somebody help to fix it?

Expert must try 5-10 times to open/close order.

Maybe n=number of try, and please without "while".

Thanks a lot.

Files:
test.mq4  9 kb
 

My code for 'adjust lots after loss',need help..thanks

My code below for 'adjust lots after loss', but it did an error massage "incorrect start position 0 for ArraySort function" during Testing. Anyone can help me to fix it? need help..

double AdjtLotsByWinRate( int magicnumber,double NormLots)

{

int i,counter;

int ProfitAndTime[][2];

double Profits[];

//----

ArrayResize(ProfitAndTime,OrdersHistoryTotal());

for (i=0;i<OrdersHistoryTotal();i++)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))

{

if (OrderType()<=OP_SELL && OrderMagicNumber()==magicnumber ) // 0 OP_BUY 1 OP_SELL 2 OP_BUYLIMIT 3 OP_SELLLIMIT 4 OP_BUYSTOP 5 OP_SELLSTOP

{

ProfitAndTime[counter][0]=OrderCloseTime();

ProfitAndTime[counter][1]=OrderProfit();

counter++;

}

}

}

ArrayResize(ProfitAndTime,counter);

ArrayResize(Profits,counter);

ArraySort(ProfitAndTime);

for (i=0;i<counter;i++)

{

Profits=ProfitAndTime[1];

}

//Print(Profits);

int err=GetLastError();

int WinRate_N=0,WinRate_A=5;

double WinRate;

for (i=counter;i<counter-WinRate_A+1;i--)

{

if (Profits>0){

WinRate_N=WinRate_N+1;

}

else if (Profits<0)

{

WinRate_N=WinRate_N-1;

}

else

{

WinRate_N=WinRate_N+0;

}

}

WinRate=WinRate_N/WinRate_A;

double NewLots;

if (WinRate>=0.7)

{

NewLots=NormLots*1.5;

}

else if (WinRate>=0.5 && WinRate<0.7)

{

NewLots=NormLots*1;

}

else if (WinRate>=0.3 && WinRate<0.5)

{

NewLots=NormLots*0.5;

}

else //if (WinRate<0.3)

{

NewLots=NormLots*0.1;

}

return(NewLots);

}

Reason: