How to code? - page 88

 
flourishing:
how to make comment(1 / 2) display 0.5 ? thank you.

Please, try this:

Comment(DoubleToStr(1/2, 1));

The second argument of the function DoubleToStr() is the number of digits after the decimal point.

 
ak97052d:
hello

how to code this:

I need to extract some info from last closed trade,

and after use some info from this last trade

ex:

if last trade profit >0 'lasttradeprofit = 1'

and if last trade <=0 'lasttradeprofit = 0'

lasttradeprofit = 1 // if last trade >0

lasttradeprofit = 0 // if last trade <=0

thanks

It's easy to scan the history and check OrderCloseTime() :

datetime LastCloseTime;

bool LastTradeIsProfit;

for(int i = 0; i > OrderHistoryTotal(), i ++)

{

OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);

if(OrderMagicNumber() != Magic) continue;

if(OrderCloseTime() > LastCloseTime)

{

LastCloseTime = OrderCloseTime();

LastTradeIsProfit = (OrderProfit() > 0);

}

}
 
ak97052d:
hello try this !

thank you for edite expert

can you change this ea using my idea

from my idea after opening two orders we explain this info

1- all orders have fix stop loss same 10pip

2-if the first order going to profit opening 2* same this order but tp=fist order tp-fix sl

3- traling sl to second order opening place

exampel:

eur/usd

on the first price is : 1.5200

1-opening two orders ( buy@ 1.5200 0.1 lot size sl=10 tp 50 & sell@1.5200 0.1 lot size sl=10 tp=50)

price go to 15210

2-at this time (my sell order will be close & will opening second buy order 0.2 lot size by sl=10 tp=40 and fist order sl traling to 1.5210 )

price go to 1.5220

3-at this time (opening buy order 0.4 lot size by sl=10 tp=30 and two befor orders sl traling to 1.5220)

4-.....

5....

if the price going to 1.5250 all orders will be close by 560$

but at this time our orders sl we only lossing 60$

this method have very best risk

 
ak97052d:
hello try this !

excuse me this expert sl have to using this formul for having profit result on thefix sl have bad result

order sl = ((MaxTrades*MinGS)+SL) - (n*MinGS)

exampel for this info

extern int MinGS=5;

extern int TP=20;

extern int SL=10;

extern double lot=0.10;

extern int MaxTrades=7;

extern int RegularSpread=2;

extern double Multiplier=2;

extern double LotInc=0;

extern double MarginLevelAlert=1000;

we have

first order sl= ((7*5)+10)-(0*5)=40

second order sl= ((7*5)+10)-(1*5)=35

and other sl are

35

30

25

20

15

 
 

Wolfe's Question

wolfe:
Does anyone know how to code so that when you call an indicator in an EA it automatically attaches the called indicator to the chart your EA is attached to? This way it would visually be in the exact same time as what is being read by your EA. Thanks.

The previous reply was incomplete.

If the indicator is standard in MT4, it will show up in the normal place. If it is called by iCustom, it will also show up, if coded right.

The following EAs even have the indicators show on the chart window. Study them to learn how:

bouncingPipEA_mpowerV42.mq4

bouncingPipEA_BigBear_v23.mq4

Big Be

 

Spread in Pending Order

Hi folks,

I made an EA that calculates daily hi-low between some period, and then place pending orders buystop/sellstop, that will expired in 12 hours.

I run it in GBP-JPY pair (8 pips spread in my broker)

int ticket, SL, TP; //SL= StopLoss , TP= TakeProfit

int Spacing = 10; // Spacing Pips

double vAsk = HighestPrice+Spacing*Point; // raise/lower 10 pips for OP Buystop/Sellstop , HighestPrice= some highest price

ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,vAsk,0,vAsk-SL*Point,vAsk+TP*Point,"Pending Order BUY STOP",20070125,CurTime() + 12 * 3600,Green);

The result, Pending Order Buy Stop was executed, even price did not touch it. I have traced the OP Buy Stop, placed at price 204.08, but it was executed when the price is at 204.00. It seems that Spread factor is involved.

My friend told me that manual Pending Order Buystop/Sellstop is executed without spread factor, but why it's different with placing order by EA ?

So is there any mistakes in my code ?

Thanks in advance.

 
mastoto:
Hi folks,

I made an EA that calculates daily hi-low between some period, and then place pending orders buystop/sellstop, that will expired in 12 hours.

I run it in GBP-JPY pair (8 pips spread in my broker)

int ticket, SL, TP; //SL= StopLoss , TP= TakeProfit

int Spacing = 10; // Spacing Pips

double vAsk = HighestPrice+Spacing*Point; // raise/lower 10 pips for OP Buystop/Sellstop , HighestPrice= some highest price

ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,vAsk,0,vAsk-SL*Point,vAsk+TP*Point,"Pending Order BUY STOP",20070125,CurTime() + 12 * 3600,Green);

The result, Pending Order Buy Stop was executed, even price did not touch it. I have traced the OP Buy Stop, placed at price 204.08, but it was executed when the price is at 204.00. It seems that Spread factor is involved.

My friend told me that manual Pending Order Buystop/Sellstop is executed without spread factor, but why it's different with placing order by EA ?

So is there any mistakes in my code ?

Thanks in advance.

If your "HighestPrice" is a BID price as they are on all charts, you probably have to add the spread. Any BUY order is triggered by a ASK price.

 

how to get the information on the main chart

i have downloaded an indicator,which shows green/red arrow when the buy/sell signal come.

now i want to program my own EA based on this indicator.

but i have only the ex4 file of this indicator(no source code)

I want my EA read the indicator arrow on the mainchart and send the buy/sell order(green arrow==>buy, red arrow==>sell)

is there any approach to get indicator arrow information on the main chart?

thanks

 
shanyang:
i have downloaded an indicator,which shows green/red arrow when the buy/sell signal come.

now i want to program my own EA based on this indicator.

but i have only the ex4 file of this indicator(no source code)

I want my EA read the indicator arrow on the mainchart and send the buy/sell order(green arrow==>buy, red arrow==>sell)

is there any approach to get indicator arrow information on the main chart?

thanks

The EA has to call the indicator signals up/down with the iCustom(); function. You don't need the source code to do this.

FerruFx