Please guide me regarding spread - page 3

 
EA starts 
---> Does nothing till there is 0 or 1 order 
----> Makes a 'call open sound' when 2nd order gets triggered 
----> Closes both orders at X amount of pure profit [after considering spread] and makes a 'call close sound' ]

of course, call open and call close sound files can be any small wave files.. easily available on mt4 itself. .. 
I think these things can be achieved in the above EA that I had posted by changing a few things !
Wow .. what you want is basically pretty easy to code.
 
deysmacro:
Wow .. what you want is basically pretty easy to code.


Can you guide me to it? I already have this from web

//+------------------------------------------------------------------+
//|                    CloseTrades_After_Account_Profit_Reached.mq4  |
//|                                     Copyright © 2007, Tradinator |
//|                                          tradinator.fx@gmail.com |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2007, Tradinator"
#property link      "tradinator.fx@gmail.com"


                                       
extern double My_Money_Profit_Target=100;     //The amount of money profit at which you want to close ALL open trades.
extern string Profit_Target= "Enter above To Close all OPEN trades when amount of profit is Reached in Account and not per OPEN trade! ";
                                          
int Slippage=5;
int i;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+


int start()
{
if (AccountProfit()>= My_Money_Profit_Target)
   {
    for(i=OrdersTotal()-1;i>=0;i--)
       {
       OrderSelect(i, SELECT_BY_POS);
       int type   = OrderType();
               
       bool result = false;
              
       switch(type)
          {
          //Close opened long positions
          case OP_BUY  : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Pink);
                         break;
               
          //Close opened short positions
          case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Pink);
                          
          }
          
       if(result == false)
          {
            Sleep(0);
          }  
       }
      Print ("Account Profit Reached. All Open Trades Have Been Closed");
      return(0);
   }  
   
   Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),
           "\nMy Account Profit Target: ",My_Money_Profit_Target);
   
  return(0);
}

Now, I have made it very clear that I am no coder, but I think I need some line below "int start()" which counts number of EXECUTED [non pending] orders and then goes on to next code only if they are 2 and executes the rest of code.. if (AccountProfit()>= My_Money_Profit_Target).. etc

right? How to say such line in MQL ?

int start()
{
 {
   if (Ordertotal()<=1)  ------>   See , something here which says only execute lower code if total executed orders are two else dont go to lower code.. I know that syntax is totally busted, trying to push the concept                                                                                                             
                                   as a weak non coder mind ;( .. so till total open orders are less than or equal to 1 means not 2, the code below that line wont come into play !         

      if (AccountProfit()>= My_Money_Profit_Target)
   {
    for(i=OrdersTotal()-1;i>=0;i--)
       {
       OrderSelect(i, SELECT_BY_POS);
 
thrdel:

Yes deVries,

everything fails and I shouldn't do that if you say so, but since I really don't see much help in you answer .....

You do understand that the code isn't a commercial EA intended for sale to a fussy customer, right We are trying to work something out and if you don't want to help, you should at least leave it alone.

You really reckon that if I change the time frame several times..... what? The Slippage will be 3000000 ? Not in my MT4 apparently. And if you don't believe me, run a test yourself.

My test says that when you change the time frames, the EA goes trough deinit/init cycle and since the code mentioned is in the OnInit, Slippage will be right at 30 point every time.

As anyone can see, changing time frames will not bring the Slippage to a million, if that's what you're suggesting.

And no, it isn't a fake picture, it's real, you can check the time of changing each time frame.

Hope it helps.


this fails .....

for lot of trades prc is not the right price

what do you have to say about that...

read Double Calls to OnInit() and OnDeinit()

there are problems with new versions

(The double OnInit() issue appears to be fixed in build 628 but have still not this version )

 
deVries:

this fails .....

for lot of trades prc is not the right price

what do you have to say about that...

hehehe, now you two have gone deep into the rabbit hole and are discussing something which is making birds fly over my head ! xD .. could you please look at that lame code line that I added? =D

 
tatyawinchu:

hehehe, now you two have gone deep into the rabbit hole and are discussing something which is making birds fly over my head ! xD .. could you please look at that lame code line that I added? =D


Correct Ask and Bid are the prices of chartSymbol if the trade is other Symbol closingprice is wrong

       if(result == false)
          {
            Sleep(0);
          }  

what effect will this have ??

is it failing??? OrderType is pending trade ???

or is it closing fails

that case you need to get last error GetLastError() knowing the reason

 
tatyawinchu:

EA starts ---> Does nothing till there is 0 or 1 order ----> Makes a 'call open sound' when 2nd order gets triggered ----> Closes both orders at X amount of pure profit [after considering spread] and makes a 'call close sound' ]

of course, call open and call close sound files can be any small wave files.. easily available on mt4 itself. .. I think these things can be achieved in the above EA that I had posted by changing a few things ! hehehe help me plz =D

Hi tatyawinchu,

I believe you didn't understand well what the EA posted does. Let me walk you trough step by step and you decide if it is something you can or cannot use for your purpose.

The stop loss based on account is there to protect anyone who wants to use it and I would never recommend to be in the market without at least an emergency stop, if you have 10 000 in your account and you want to risk it all, just set the StopLossLimit to 10 000.

Your decision.

Now, back to the code, it's as easy as 1, 2, 3 :

1. If you read the code in the OnTick function - that is the part that gets executed on every tick - you will see the first thing it does is : CountMyOrders. Hope you see that. Next, if myOrders <1 means there are no orders yet, checks the account equity, remembers it and that it.

Does nothing else. Next tick, if still no orders, back to waiting. Pretty boring to be an EA, ins't it ?

2.When an order is placed myOrders<1 isn't true any more so at the next tick, it will jump over to the next line and calculate the profit for the order or orders that are in the market.

3.Next, it will compare the sum of all orders profit with the target profit.

Easy, isn't it. If the profit reaches the target, next line says : ExitAll . And will pop up an alert (with sound) on the screen telling you that orders have reached their target !

Wasn't so bad, was it ?

And I forgot to mention, if the market goes against you and the loss of equity reaches the preset level, it will take you out of the market to protect whatever capital is left.

And that's the best help I could give you.

If you need more than that, it's probably a job for the guys who do more custom code than this.

Hope it helps.

Cheers

 
thrdel:

Hi tatyawinchu,

I believe you didn't understand well what the EA posted does. Let me walk you trough step by step and you decide if it is something you can or cannot use for your purpose.

The stop loss based on account is there to protect anyone who wants to use it and I would never recommend to be in the market without at least an emergency stop, if you have 10 000 in your account and you want to risk it all, just set the StopLossLimit to 10 000.

Your decision.

Now, back to the code, it's as easy as 1, 2, 3 :

1. If you read the code in the OnTick function - that is the part that gets executed on every tick - you will see the first thing it does is : CountMyOrders. Hope you see that. Next, if myOrders <1 means there are no orders yet, checks the account equity, remembers it and that it.

Does nothing else. Next tick, if still no orders, back to waiting. Pretty boring to be an EA, ins't it ?

2.When an order is placed myOrders<1 isn't true any more so at the next tick, it will jump over to the next line and calculate the profit for the order or orders that are in the market.

3.Next, it will compare the sum of all orders profit with the target profit.

Easy, isn't it. If the profit reaches the target, next line says : ExitAll . And will pop up an alert (with sound) on the screen telling you that orders have reached their target !

Wasn't so bad, was it ?

And I forgot to mention, if the market goes against you and the loss of equity reaches the preset level, it will take you out of the market to protect whatever capital is left.

And that's the best help I could give you.

If you need more than that, it's probably a job for the guys who do more custom code than this.

Hope it helps.

Cheers


Hmm.. looks like we are drifting apart ..

My exact requirement is as follows:-

Step1 EA starts .

Step 2 EA checks for current account profit so that it knows the start point to calculate from.

Step 3 EA checks for running open orders [not pending].

Step 4 EA does nothing if there is no running order OR there is just ONE running order.

Step 5 EA makes a sound when SECOND order gets triggered .. This second order will be on some other pair.

Step 6 EA closes BOTH the orders at X profit after taking into consideration the SPREAD and make a sound.... here BOTH should be ALL open orders .. does not need to delete pending orders

What the EA does not need .. SL or TP setting of any kind..

Preferably, EA should work on orders more than two, but not needed if its too difficult..

[ Though logically I feel it wont be difficult, rather very easy, because EA activates to close ALL open orders if they are MORE THAN 1 .. thats 2 or MORE automatically! so that may be already covered by EA.. correct me if wrong!]

 
deysmacro:
Wow .. what you want is basically pretty easy to code.

You're funny. Subtle but funny.
 
thrdel:

You're funny. Subtle but funny.

what if I can add an IF loop and then paste the rest of the code below which starts the loop?

The IF condition should check the OrdersTotal to be => 2 so that control is passed to close all open orders at X profit after spread?

How to tell EA to do noting in certain case?

Say I do the following

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+


int start() 
{
if (OrdersTotal()=>2)                                     // Can this work? Can a function be directly called like this?
} 
{
 if (AccountProfit()>= My_Money_Profit_Target)
   {
    for(i=OrdersTotal()-1;i>=0;i--)
       {
       OrderSelect(i, SELECT_BY_POS);
       int type   = OrderType();
               
       bool result = false;
              
       switch(type)
Ok, cant seem to get out of this box yet ! hehe need to know forum stuff more ! but, as you can see above, if that "if (OrdersTotal()=>2)" is valid, it would directly solve my problems .. because the rest of
the stuff would be executed only if the total running market orders are 2 ! =D ..  and some forum guru please release this text from this src prison box ! ;)
 
You must remember though. The EA closes running trades only. You have to open trade yourself.
Reason: