Ask! - page 77

 

To CodersGuru : need help about 10 points 3 EA....

Hi CodersGuru,

I am new to forex trade and new to this forum too. First time, I am learning is EuroX2_sl, extended from 10 points 3 EA script. After did a few forward test, this EA did Open Position well but it did not Close Position well as I need to when market reverse. Maybe, something is wrong with the code ( cos' I am not a programmer ) and I think I need your help to solve it. Could please check which part may be wrong ?

Condition is :

1. OPEN BUY when indicator condition exist. ie: stochastic

2. CLOSE BUY when OPEN SELL indicator exist. ie:stochastic

3. OPEN SELL as the indicator condition ( no. 2 above ) exist. ie : stochastic

4. CLOSE SELL as the indicator condition ( no. 1 above ) exist. ie : stochastic

I think OPEN position is okay but the problem is with the CLOSE POSITION as it did not CLOSE ( BUY or SELL ) even when the indicator exist.

The code as I did is :

-------- part of script from EuroX2_sl extended from 10 points 3 as I think for close position -------

// it is important to enter the market correctly,

// but it is more important to exit it correctly...

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

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL && // check for opened position

OrderType()<=OP_BUY &&

OrderType()>=OP_SELL &&

OrderType()>=OP_BUY &&

OrderSymbol()==Symbol()) // check for symbol

{

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

if(OrderType()==OP_BUY) // long position is opened

{

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

//+ CONDITION FOR CLOSE POSITION

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

//+--------------- CLOSE BUY POSITION ----------------------------

if ( Stoch_Main_M15_Cu < Stoch_Sig_M15_Cu )

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

{

OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ; // close position

return(0); // exit

}

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

// check for trailing stop

if(TrailingStop>0)

{

if(Bid-OrderOpenPrice()>Point*TrailingStop)

{

if(OrderStopLoss()<Bid-Point*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);

return(0);

}

}

}

}

//+---------------CLOSE SELL POSITION --------------------------------

else // go to short position

{ //+ DO NOT REMOVE

if(OrderType()==OP_SELL) // short position is opened

{

}

// should it be closed?

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

if ( Stoch_Main_M15_Cu > Stoch_Sig_M15_Cu )

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

{

OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet) ; // close position

return(0); // exit

}

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

// check for trailing stop

if(TrailingStop>0)

{

if((OrderOpenPrice()-Ask)>(Point*TrailingStop))

{

if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);

return(0);

}

}

}

}

}

}

--------------------------------------------------------------

Thank you,

fxgroup

 

Reading data from another currency pair window

My EA is on "GBPJPY" window, but I need to find ObjectDescription() form another window, say "USDJPY". (Unfortunately, it's a Pivot indicator which doeasn't return values from iCustom())

Anybody knows the way to refer to another (not current) pair window to be able to use functions like ObjectDescription() on it?

Or MQ4 doesn't allow it?

Thank you

euro

 

How do I isolate profits of one currency from others??

color color_of_pipsprofit;

color_of_pipsprofit = White;

int m,totalbuy;

totalbuy=OrdersTotal();

for(m=0;m<totalbuy;m++)

OrderSelect(m, SELECT_BY_POS, MODE_TRADES);

if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber() == Reference)

{

pips_profit=OrderProfit();

}

if(pips_profit >= 0)

{

color_of_pipsprofit = Lime;

}

else {color_of_pipsprofit = Red;

}

int n,totalsell;

totalsell=OrdersTotal();

for(n=0;n<totalsell;n++)

OrderSelect(n, SELECT_BY_POS, MODE_TRADES);

if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber() == Reference)

{

pips=OrderProfit();

}

if(pips_profit >= 0)

{

color_of_pipsprofit = Lime;

}

else {color_of_pipsprofit = Red;

}

ObjectCreate("pips_profit", OBJ_LABEL, 0, 0, 0);

ObjectSetText("pips_profit",DoubleToStr(pips_profit,2),14, "Verdana", color_of_pipsprofit);

ObjectSet("pips_profit", OBJPROP_CORNER, 3);

ObjectSet("pips_profit", OBJPROP_XDISTANCE, 35);

ObjectSet("pips_profit", OBJPROP_YDISTANCE, 20);

}

I created this coding, but I cannot isolate the profits of one currency from other currencies being traded. What am I lacking in my code??

Please review. Thanks for your help!

Dave

 

Profit

Try this code:

int start()

{

int total = OrdersTotal();

for (int cnt = total ; cnt >=0 ; cnt--)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)

{

Print(Profit(OrderType(),OrderSymbol(),OrderOpenPrice());

}

}

return(0);

}

double Profit(int type, string currency, double open)

{

if(type==OP_BUY) return((MarketInfo(currency,MODE_BID) - open) / MarketInfo(currency,MODE_POINT) ); //case buy

if(type ==OP_SELL) return((open - MarketInfo(currency,MODE_ASK)) / MarketInfo(currency,MODE_POINT)); //case buy

return(-1);

}[/php]

1Dave7:
[php]

color color_of_pipsprofit;

color_of_pipsprofit = White;

int m,totalbuy;

totalbuy=OrdersTotal();

for(m=0;m<totalbuy;m++)

OrderSelect(m, SELECT_BY_POS, MODE_TRADES);

if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber() == Reference)

{

pips_profit=OrderProfit();

}

if(pips_profit >= 0)

{

color_of_pipsprofit = Lime;

}

else {color_of_pipsprofit = Red;

}

int n,totalsell;

totalsell=OrdersTotal();

for(n=0;n<totalsell;n++)

OrderSelect(n, SELECT_BY_POS, MODE_TRADES);

if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber() == Reference)

{

pips=OrderProfit();

}

if(pips_profit >= 0)

{

color_of_pipsprofit = Lime;

}

else {color_of_pipsprofit = Red;

}

ObjectCreate("pips_profit", OBJ_LABEL, 0, 0, 0);

ObjectSetText("pips_profit",DoubleToStr(pips_profit,2),14, "Verdana", color_of_pipsprofit);

ObjectSet("pips_profit", OBJPROP_CORNER, 3);

ObjectSet("pips_profit", OBJPROP_XDISTANCE, 35);

ObjectSet("pips_profit", OBJPROP_YDISTANCE, 20);

}

I created this coding, but I cannot isolate the profits of one currency from other currencies being traded. What am I lacking in my code??

Please review. Thanks for your help!

Dave
 
codersguru:
Try this code:
int start()

{

int total = OrdersTotal();

for (int cnt = total ; cnt >=0 ; cnt--)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)

{

Print(Profit(OrderType(),OrderSymbol(),OrderOpenPrice());

}

}

return(0);

}

double Profit(int type, string currency, double open)

{

if(type==OP_BUY) return((MarketInfo(currency,MODE_BID) - open) / MarketInfo(currency,MODE_POINT) ); //case buy

if(type ==OP_SELL) return((open - MarketInfo(currency,MODE_ASK)) / MarketInfo(currency,MODE_POINT)); //case buy

return(-1);

}

Hi Coder,

This was not exactly what I need. I am attaching a graph picture to illustrate what I am looking for. Can you modify the coding to display the Profit? If so, I can get the colors to change on the Profit amount. I am just looking for the profit for each specific currency.

 

indicator attatched

Hi Codersguru

im wishing for the attatched indicator to show open at gmt midnight, and not the brokers server time, is this possible

many thanks monty

 

Help with code

Can you step through the code? I'm getting a value incorrect (see below "Account") and then its being corrrectly populated but i'm not sure why.

int Account = 123456;

if (Account != AccountNumber())

{

Comment("You can not use this program with this account");

return (0);

}

else

{

Comment("Welcome to Program");

}

 

Simple question

Will the expert advisor run normally without init() and deinit() functions?

 
n7drazen:
Will the expert advisor run normally without init() and deinit() functions?

Yes,

Only start function is required.

 

Kalenzo,

I have a question:

HEDGING:

I'm looking for:

if (OrderOpenPrice() = = Bid (or Ask)

Opened price must be equal as new price.

I hedging with same pair EURUSD.

If opened price is sell and price is 1.3580,

buy price must be the same.

Thanks. Here are the codes.

B.

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

if(Buy==0)

{

RefreshRates();

OrderSend(Symbol_1,OP_BUY,lotsi,MarketInfo(Symbol_ 1,MODE_ASK),...

RefreshRates();

if (OrderOpenPrice() == Bid)

{

OrderSend(Symbol_1,OP_SELL,lotsi,MarketInfo(Symbol _1,MODE_BID),...

}

Reason: