Reply

CustomFunction to close orders at current profit

3 replies

Mike H.

Subscriber, bbp_participant, community, 76 replies.

Visit profile

10 years ago #111629

I ended up putting said code into a simple custom indicator using buffers to be recognized by the EA Wizard. I will see on Monday if the EA being created will close orders as needed by utilizing the custom indicator’s buffer. Actually, the main problem I have is being able to understand where to put and how to utilize a FUNCTION within the EA Wizard. You can tell me to put the FUNCTION into the customfunction.mq4 ??? I’m not a wizard at writing code, which is why I purchased the EA Wizard. Will someone please explain to me, where & how do I plug a FUNCTION into the EA Wizard software so the EA Wizard can utilize it ???

 

Guess I figured it out. See Attached File…

double profit()

{

   OrderSelect(NULL,0);

   double profit = OrderProfit() + OrderSwap();

   return (profit);

}

 

Revision made since first posted. (only one error left)

I need a Custom Function condition which will simply get the current profit from an open order. So, if the value of the function is greater than zero, then the EA will close the open orders on Fridays. I’m trying to figure out how to add the following function into C:\SQ_EAWizard\code\CustomFunctions.mq4. I think the following function will work?
double profit();

 

REVISION:

double profit();
{
   OrderSelect();
   double profit = OrderProfit(NULL) + OrderSwap(NULL);
   return (profit);
}

 

1 error:

1:8;’profit’ – no dll defined for the imported function

 

OLD:

{
   OrderSelect();
   profit = OrderProfit() + OrderSwap();
   return (profit);
}
I’m trying to add that function to CustomFunctions.mq4:
double exampleFunction(double value) {
   return(2 * value);
}
How do I make it so the profit variable will not be global?
When I compile, why do I get an error about not being able to import a .dll file?

0

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

10 years ago #122753

I replied to you in another thread, I also posted an example of profit function.

 

Here’s the default function used by EA Wizard to determine open profit (without swaps and commissions), you can copy it using different name

and alter it so that it will include also swaps and commissions.

 

double sqGetOpenPLInMoney(int orderMagicNumber) {
   double pl = 0;
 
   for (int cc = OrdersTotal() – 1; cc >= 0; cc–) {
      if (!OrderSelect(cc, SELECT_BY_POS) ) continue;
      if(OrderType() != OP_BUY && OrderType() != OP_SELL) continue;
      if(OrderSymbol() != Symbol()) continue;
      if(orderMagicNumber != 0 && OrderMagicNumber() != orderMagicNumber) continue;
 
      pl += OrderProfit();
   }
 
   return(pl);
}

 

I’m not sure why there is dll error call, it looks like MT4 cannot find the function. Can you check your EA if your function is there?

 

Mark

Mark
StrategyQuant architect

0

Mike H.

Subscriber, bbp_participant, community, 76 replies.

Visit profile

10 years ago #122762

Yes Mark,

       I remember looking at that condition. I passed on using it because it didn’t include the swap. I’m not concerned about commission because I pay by spread…

Maybe I can modify the code before compiling… Actually, I’ve been modifying the code for Order Opened This Minute & Order Closed This Minute to 1320 seconds instead of 60 seconds. 60 seconds is not long enough to see if the Currency Pair’s direction might change…

0

Mike H.

Subscriber, bbp_participant, community, 76 replies.

Visit profile

10 years ago #122770

My Custom Indicator where the OpenProfit function was used within has worked very well. It even calculated the Swap as well.

0

Viewing 3 replies - 1 through 3 (of 3 total)