Download MetaTrader 5
To add comments, please log in or register
How to buy a product in MetaTrader AppStore? Read the article!
Quanti
81
Quanti 2016.03.29 07:44 

I have an EA i made, and i want to know if it is possible to just copy and paste the code for opening a pending limit order, with magic number into a script format. This would also include parameters for money management inputs in my EA and i would like it to also incorporate the trailing stop i have entered in my EA.

 

Can i do that? Would i do it under OnStart?

I tried and it compiled but when dragged on the chart it didn't do anything or open any orders. I would like this for when i find trades that i have not coded my EA to find, simply to open orders with the same settings with the Trailing Stop.

Keith Watford
Moderator
7892
Keith Watford 2016.03.29 08:30  
Show the code for the script. It is definitely possible.
Quanti
81
Quanti 2016.03.29 08:58  
GumRai:
Show the code for the script. It is definitely possible.

This is an example i quickly made to show what i want it to do. To simply open pending orders with trailing stop and break evens. All input parameters and include parameters i left out but obviously i would insert it to make the code compile. I just want to understand the concept and if this is the framework i would make it in to make it run. If so, the rest i can solve. The thing is, since this is not a market order but a pending order, would i incorporate an input for that so i can type the price in when it is dragged onto the chart. 

//+------------------------------------------------------------------+
//|                                                        order.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
OrderSend(_Symbol,OP_SELLLIMIT,lotSize,"(Price Input),2,StopLoss,0,"Sell Limit Order",102,0,clrRed);

if(UseBreakEvenStop == true)
{
BreakEvenStopAll(aMinProfit,aLockProfit);
   
  }
if(UseTrailingStop == true)
{
TrailingStopAll(aTrailingStop,aMinimumProfit,Step);
}
//+------------------------------------------------------------------+
Keith Watford
Moderator
7892
Keith Watford 2016.03.29 09:21  

If that script code doesn't open an order, then there is something wrong with the price input or the StopLoss parameters.

Break Even and Trailing stop should be dealt with by an EA, not a script as a script only runs once.

Quanti
81
Quanti 2016.03.29 09:44  
GumRai:

If that script code doesn't open an order, then there is something wrong with the price input or the StopLoss parameters.

Break Even and Trailing stop should be dealt with by an EA, not a script as a script only runs once.

GumRai, i got it to work successfully thank you, so i established all orders within the script to contain the same magic number my EA uses to manage orders via Trailing Stop and Break evens. Will the EA pick up on these script orders through the same Magic Number as long as it is running and manage them to have a trailing stop? This is what i am going for. Thank you
Keith Watford
Moderator
7892
Keith Watford 2016.03.29 11:29  
quanti:
GumRai, i got it to work successfully thank you, so i established all orders within the script to contain the same magic number my EA uses to manage orders via Trailing Stop and Break evens. Will the EA pick up on these script orders through the same Magic Number as long as it is running and manage them to have a trailing stop? This is what i am going for. Thank you
If the script sets the same magic number as the EA, then the EA will manage the trade
whroeder1
13602
whroeder1 2016.03.29 12:46  
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. OrderSend(_Symbol,OP_SELLLIMIT,lotSize,"(Price Input),2,StopLoss,0,"Sell Limit Order",102,0,clrRed);
    At least post code that compiles.
  3. Check your return codes and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Quanti
81
Quanti 2016.03.29 13:50  
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. At least post code that compiles.
  3. Check your return codes and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
I got it working already thank you
/
To add comments, please log in or register