Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.
From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.
Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
Elite Section
Get access to private discussions, specialized support, indicators and trading systems reported every week.
Advanced Elite Section
For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
Hi. I'm trying to use my EA to control an indicator I've written. I have exposed an extern double in the indicator which it uses on every tick to set its horizontal level. If it gets no new info in continues on its present course. I want to use the indicator as a stop out so I need the EA to be able to synchronize buy in and sell outs.
I assumed using double somedisposedofvalue = iCustom(null, 0, "AntariesRising", [value], 0, 0);
would restart the constructor or at least update the variable, but this doesn't appear to be the case. I'm not sure if its creating an off screen instance of the indicator or its using the one I've instantiated, or if theres just another function I can call custom extern variables from.
Above is the code for the indicator. Simply, it draws a line that should be updatable via the EA using the intiially mentioned code:
Code:
temp = iCustom(NULL, 0, "AntariaRising", 200, 1.2, 0, 0); //temp not used. Function returns a double
I guess I want to replace the final piece of code that actually allows me to update into the incicator object the variable that its tracking on, so that I can later use it as a stop-out line. The remaining code is irrelevant however. When I run the above function i expect antaria to move position from 1.39 or whatever it starts on, to 1.2. I can't remember if I use the 200 variable. I think I've chopped out my header and footer comments, but the entire slave indicator is up there, which is AntariaRising meantioned in immediately above code
this was the only function I could find that talked to indicator objects, and I use it to read off values in other areas.
i want someone to help me with this code it open trade when i want it but close it automatically so i want it to trade with stop loss not closing when not crossing again this is the code
//+------------------------------------------------------------------+
//| JR300.mq4 |
//| onelove |
//| Forex Forum | Forex Tsd | Metatrader Forum |
//+------------------------------------------------------------------+
#property copyright "oneLove"
#property link "http://www.forex-tsd.com"
//---- input parameters
extern double TakeProfit=250.0;
extern double Lots=0.1;
extern double TrailingStop=35.0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
int Crossed (double line1 , double line2)
{
static int last_direction = 0;
static int current_direction = 0;
if(line1>line2)current_direction = 1; //up
if(line1<line2)current_direction = 2; //down
if(current_direction != last_direction) //changed
{
last_direction = current_direction;
return (last_direction);
}
else
{
return (0);
}
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int cnt, ticket, total;
double shortEma, longEma;
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return(0); // check TakeProfit
}
shortEma = iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,0);
longEma = iMA(NULL,0,200,0,MODE_SMA,PRICE_CLOSE,0);
int isCrossed = Crossed (shortEma,longEma);
total = OrdersTotal();
if(total < 1)
{
if(isCrossed == 1)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+ TakeProfit*Point,
"My EA",12345,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))
Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
if(isCrossed == 2)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,
Bid-TakeProfit*Point,"My EA",12345,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))
Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?
if(isCrossed == 2)
{
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);
}
}
}
}
else // go to short position
{
// should it be closed?
if(isCrossed == 1)
{
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+Poi nt*TrailingStop,
OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}
//+------------------------------------------------------------------+
Thanks Roger, I've removed that second limit declaration from my start function. I'm surprised the compiler was allowing that one, but it hadn't impacted my program noticably.
Still I am unsure how to alter the running instance of that indcator from my EA. A method would be much appreciated, or at least confirmation that the API does not currently allow me to pass information to running indicators.
Thanks.
[UPDATE: The code was holding me up too much so I've opted for GlobalVariableSet/Get. Its not optimal for obvious reasons, but it gets the job done]