- Programmer needed for custom indicator and EA
- How to code?
- Getting Value from Gann HiLo - Indicator to my EA
depends where the declaration "double Gann = ..." is located in your EA source code.
IF in a function it is local to that function and only code in the function can reference/see Gann
IF outside of all functions (an EA global) then any code in the EA can reference/see Gann
BUT... only a function level (local) declaration can have an expression as an initial value as you show.
all global declarations or local declarations with static attribute - can only have constant initial value and not expression.
see MetaEditor editor help
really... would be easier to see your code, then all would become clear.
regards
depends where the declaration "double Gann = ..." is located in your EA source code.
IF in a function it is local to that function and only code in the function can reference/see Gann
IF outside of all functions (an EA global) then any code in the EA can reference/see Gann
BUT... only a function level (local) declaration can have an expression as an initial value as you show.
all global declarations or local declarations with static attribute - can only have constant initial value and not expression.
see MetaEditor editor help
really... would be easier to see your code, then all would become clear.
regards
Thank you so much for responding to me. I have all of one weeks worth of programming skills and most of what I learned was from paying a programmer to write an EA that I knew would not work but I needed a starting point. If you have something that works then you have a chance of modifying it and making it work. I now understand the error message that I got when compiling my program. I first tried writing the entire program and then compiling it and another programmer told me to compile one line at a time. This was an immense help.
depends where the declaration "double Gann = ..." is located in your EA source code.
IF in a function it is local to that function and only code in the function can reference/see Gann
IF outside of all functions (an EA global) then any code in the EA can reference/see Gann
BUT... only a function level (local) declaration can have an expression as an initial value as you show.
all global declarations or local declarations with static attribute - can only have constant initial value and not expression.
see MetaEditor editor help
really... would be easier to see your code, then all would become clear.
regards
Thank you so much for responding to me. I have all of one weeks worth of programming skills and most of what I learned was from paying a programmer to write an EA that I knew would not work but I needed a starting point. If you have something that works then you have a chance of modifying it and making it work. I now understand the error message that I got when compiling my program. I first tried writing the entire program and then compiling it and another programmer told me to compile one line at a time. This was an immense help.
I took about 1 hour this morning a read the sections on variables and functions and fixed my program thanks to your input. The market is not opened but I now have an EA with no errors in the compiling. I now can set it up to run on a demo account. I started with an indicator set to two different settings and modified my EA to looking at 3 indicators, One > or < PRICE_OPEN, and the other two comparing two different values within the same indicator. Not an extremely complicated program but if you have been programming for less than 2 weeks this is very acceptable to me as progress.
Good going program_ideas!
Bet you feel very satisfied about how reading paid off - I bet that next you will be reading MQL4 Tutorial in English :o)
Indeed, few weeks in and solid footsteps on MQL path.
Is nice to hear back from people... is what all about for me!
Enjoy it all
Good going program_ideas!
Bet you feel very satisfied about how reading paid off - I bet that next you will be reading MQL4 Tutorial in English :o)
Indeed, few weeks in and solid footsteps on MQL path.
Is nice to hear back from people... is what all about for me!
Enjoy it all
Thank you so much for your input. I do not really understand the function of the Heikin_Ashi_Smoothed so I am having trouble defining it as a variable in my next programming endeavor. I have read this tutorial and understand some of it but until I need to use it I am misunderstanding some of it as well. I am now trying to use the Heikin_Ashi_Smoothed as a parameter in a program. I just know that of the 3 versions of the Heikin Ashi that I have worked with that I prefer this one. What I am trying to accomplish is to use the Heikin Ashi to confirm entry or exit direction. This is what I have put in:
double HAS2 = iCustom(NULL, 0, "Heikin_Ashi_Smoothed",True, Red, 2, Current + 0);
double HAS3 = iCustom(NULL, 0, "Heikin_Ashi_Smoothed",True, RoyalBlue, 3, Current + 0);
and it says: Variable not defined. What I am trying to do is to use Parablolic Trendchaser coupled with the Heikin Ashi Smoothed for entry and exit from a program. I have had success now in writing 8 programs using the starting point of the EA I paid to have written. This has given me a good base with stop losses, take profit and other parameters already set up for me. This gave me a real head start and made it much easier for me. I also have found some of the scripts helpful in accomplishing what I am trying to do. I am basically just taking any idea that strikes me and trying to test it on a demo account. This I think will work much better than what I have been doing by coming up with a strategy and then testing it in real time with real money much of the time with disasterous results.
Would help to actually see code or failing that please right click [and copy so can paste into your post] the compiler error text you are talking about ie, what variable are you talking about... ;)
Not enough info - have no idea just what your HASmoothed uses regards: parameters and index buffers
For instance, I found on my hard drive an HA source file and it had:
//---- extern color color1 = Red; extern color color2 = White; extern color color3 = Red; extern color color4 = White; //---- buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; double ExtMapBuffer3[]; double ExtMapBuffer4[];
EG, if wanted the value from index buffer2 at ExtMapBuffer2[Current] then:
double HAS2 = iCustom(NULL, 0, "someHA", Red, White, Red, White, 1, Current + 0); //where: 1=index buffer2; and I have no idea about variable contents of Current identifier.
notice that afaik, all parameters must be listed: as in above there are 4 and must be listed left to right as declared in source file (top..bottom): color1,color2,...
and numbering of indexbuffers is from 0..7 so ExtMapBuffer2 is actually 1
also, + 0 not needed, is redundant.
double HAS2 = iCustom(NULL, 0, "Heikin_Ashi_Smoothed",True, Red, 2, Current+ 0);
double HAS3 = iCustom(NULL, 0, "Heikin_Ashi_Smoothed",True, RoyalBlue, 3, Current + 0);
double iCustom( | string symbol, int timeframe, string name, ..., int mode, int shift) |
symbol | - | Symbol the data of which should be used to calculate indicator. NULL means current symbol. |
timeframe | - | Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. |
name | - | Custom indicator compiled program name. |
... | - | Parameters set (if necessary). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator. |
mode | - | Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions. |
shift | - | Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). |
Would help to actually see code or failing that please right click [and copy so can paste into your post] the compiler error text you are talking about ie, what variable are you talking about... ;)
Not enough info - have no idea just what your HASmoothed uses regards: parameters and index buffers
For instance, I found on my hard drive an HA source file and it had:
//---- extern color color1 = Red; extern color color2 = White; extern color color3 = Red; extern color color4 = White; //---- buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; double ExtMapBuffer3[]; double ExtMapBuffer4[];
EG, if wanted the value from index buffer2 at ExtMapBuffer2[Current] then:
double HAS2 = iCustom(NULL, 0, "someHA", Red, White, Red, White, 1, Current + 0); //where: 1=index buffer2; and I have no idea about variable contents of Current identifier.
notice that afaik, all parameters must be listed: as in above there are 4 and must be listed left to right as declared in source file (top..bottom): color1,color2,...
and numbering of indexbuffers is from 0..7 so ExtMapBuffer2 is actually 1
also, + 0 not needed, is redundant.
double HAS2 = iCustom(NULL, 0, "Heikin_Ashi_Smoothed",True, Red, 2, Current+ 0);
double HAS3 = iCustom(NULL, 0, "Heikin_Ashi_Smoothed",True, RoyalBlue, 3, Current + 0);
double iCustom( | string symbol, int timeframe, string name, ..., int mode, int shift) |
symbol | - | Symbol the data of which should be used to calculate indicator. NULL means current symbol. |
timeframe | - | Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. |
name | - | Custom indicator compiled program name. |
... | - | Parameters set (if necessary). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator. |
mode | - | Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions. |
shift | - | Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). |
This gives me some idea of where to start. The more I try to do the more confused I seem to become.
Would help to actually see code or failing that please right click [and copy so can paste into your post] the compiler error text you are talking about ie, what variable are you talking about... ;)
Not enough info - have no idea just what your HASmoothed uses regards: parameters and index buffers
For instance, I found on my hard drive an HA source file and it had:
//---- extern color color1 = Red; extern color color2 = White; extern color color3 = Red; extern color color4 = White; //---- buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; double ExtMapBuffer3[]; double ExtMapBuffer4[];
EG, if wanted the value from index buffer2 at ExtMapBuffer2[Current] then:
double HAS2 = iCustom(NULL, 0, "someHA", Red, White, Red, White, 1, Current + 0); //where: 1=index buffer2; and I have no idea about variable contents of Current identifier.
notice that afaik, all parameters must be listed: as in above there are 4 and must be listed left to right as declared in source file (top..bottom): color1,color2,...
and numbering of indexbuffers is from 0..7 so ExtMapBuffer2 is actually 1
also, + 0 not needed, is redundant.
double HAS2 = iCustom(NULL, 0, "Heikin_Ashi_Smoothed",True, Red, 2, Current+ 0);
double HAS3 = iCustom(NULL, 0, "Heikin_Ashi_Smoothed",True, RoyalBlue, 3, Current + 0);
double iCustom( | string symbol, int timeframe, string name, ..., int mode, int shift) |
symbol | - | Symbol the data of which should be used to calculate indicator. NULL means current symbol. |
timeframe | - | Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. |
name | - | Custom indicator compiled program name. |
... | - | Parameters set (if necessary). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator. |
mode | - | Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions. |
shift | - | Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). |
This gives me some idea of where to start. The more I try to do the more confused I seem to become.
I thought I had an EA working. It takes way too many trades and gets out when it should stay in the market. What I was trying to do was to take an entry long when the price opened over the testing level of the Gann HiLo Activator & the
Bulls from buffer 2 was > the Bears from buffer 3. The reverse was a sell and if either indicator reversed against my position this was an exit. Here is what I was trying and I do not know why it does not work at all. #define SIGNAL_NONE 0
#define SIGNAL_BUY 1
#define SIGNAL_SELL 2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4
#property copyright "Keith Bunge"
extern string Remark1 = "== Main Settings ==";
extern int MagicNumber = 0;
extern bool SignalMail = False;
extern bool EachTickMode = True;
extern double Lots = 0.1;
extern int Slippage = 3;
extern bool UseStopLoss = False;
extern int StopLoss = 30;
extern bool UseTakeProfit = false;
extern int TakeProfit = 60;
extern bool UseTrailingStop = false;
extern int TrailingStop = 30;
extern bool MoveStopOnce = False;
extern int MoveStopWhenPrice = 50;
extern int MoveStopTo = 1;
int BarCount;
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init() {
BarCount = Bars;
if (EachTickMode) Current = 0; else Current = 1;
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int Order = SIGNAL_NONE;
int Total, Ticket;
double StopLossLevel, TakeProfitLevel;
if (EachTickMode && Bars != BarCount) TickCheck = False;
Total = OrdersTotal();
Order = SIGNAL_NONE;
//+------------------------------------------------------------------+
//| Variable Begin |
//+------------------------------------------------------------------+
double FastMain = iCustom(NULL, 0, "AbsoluteStrenghtHisto_v2", "*** Strong Trend Line *** *** Indicator Settings ***", True, 2, Current + 0);
double FastSignal = iCustom(NULL, 0, "AbsoluteStrenghtHisto_v2", "*** Weak Trend Line *** *** Indicator Settings ***", True, 3, Current + 0);
double FastMain1 = iCustom(NULL, 0, "AbsoluteStrenghtHisto_v2", "*** Strong Trend Line *** *** Indicator Settings ***", True, 2, Current + 1);
double FastSignal1 = iCustom(NULL, 0, "AbsoluteStrenghtHisto_v2", "*** Weak Trend Line *** *** Indicator Settings ***", True, 3, Current + 1);
double SlowMain = iCustom(NULL, 0, "FX5_MACD_Divergence_V1.1", "*** MACD Settings ***", 12, 26, 9, "*** Indicator Settings ***", True, True, True, 2, Current + 0);
double SlowSignal = iCustom(NULL, 0, "FX5_MACD_Divergence_V1.1", "*** MACD Settings ***", 12, 26, 9, "*** Indicator Settings ***", True, True, True, 3, Current + 0);
double SlowMain1 = iCustom(NULL, 0, "FX5_MACD_Divergence_V1.1", "*** MACD Settings ***", 12, 26, 9, "*** Indicator Settings ***", True, True, True, 2, Current + 1);
double SlowSignal1 = iCustom(NULL, 0, "FX5_MACD_Divergence_V1.1", "*** MACD Settings ***", 12, 26, 9, "*** Indicator Settings ***", True, True, True, 3, Current + 1);
//+------------------------------------------------------------------+
//| Variable End |
//+------------------------------------------------------------------+
//Check position
bool IsTrade = False;
for (int i = 0; i < Total; i ++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
IsTrade = True;
if(OrderType() == OP_BUY) {
//Close
//+------------------------------------------------------------------+
//| Signal Begin(Exit Buy) |
//+------------------------------------------------------------------+
if ((FastMain < FastSignal && FastMain1 >= FastSignal1) || (SlowMain < SlowSignal && SlowMain1 >= SlowSignal1)) Order = SIGNAL_CLOSEBUY;
//+------------------------------------------------------------------+
//| Signal End(Exit Buy) |
//+------------------------------------------------------------------+
if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
//MoveOnce
if(MoveStopOnce && MoveStopWhenPrice > 0) {
if(Bid - OrderOpenPrice() >= Point * MoveStopWhenPrice) {
if(OrderStopLoss() < OrderOpenPrice() + Point * MoveStopTo) {
OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() + Point * MoveStopTo, OrderTakeProfit(), 0, Red);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
//Trailing stop
if(UseTrailingStop && TrailingStop > 0) {
if(Bid - OrderOpenPrice() > Point * TrailingStop) {
if(OrderStopLoss() < Bid - Point * TrailingStop) {
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
} else {
//Close
//+------------------------------------------------------------------+
//| Signal Begin(Exit Sell) |
//+------------------------------------------------------------------+
if ((FastMain > FastSignal && FastMain1 <= FastSignal1) || (SlowMain > SlowSignal && SlowMain1 <= SlowSignal1)) Order = SIGNAL_CLOSESELL;
//+------------------------------------------------------------------+
//| Signal End(Exit Sell) |
//+------------------------------------------------------------------+
if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
//MoveOnce
if(MoveStopOnce && MoveStopWhenPrice > 0) {
if(OrderOpenPrice() - Ask >= Point * MoveStopWhenPrice) {
if(OrderStopLoss() > OrderOpenPrice() - Point * MoveStopTo) {
OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() - Point * MoveStopTo, OrderTakeProfit(), 0, Red);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
continue;
}
}
}
}
//+------------------------------------------------------------------+
//| Signal Begin(Entry) |
//+------------------------------------------------------------------+
if ((FastMain > FastSignal && SlowMain > SlowSignal && (FastMain1 <= FastSignal1 || SlowMain1 <= SlowSignal1)) Order = SIGNAL_BUY;
if ((FastMain < FastSignal && SlowMain < SlowSignal && (FastMain1 >= FastSignal1 || SlowMain1 >= SlowSignal1)) Order = SIGNAL_SELL;
//+------------------------------------------------------------------+
//| Signal End |
//+------------------------------------------------------------------+
//Buy
if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;
Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("BUY order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
} else {
Print("Error opening BUY order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}
//Sell
if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;
Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("SELL order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
} else {
Print("Error opening SELL order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}
if (!EachTickMode) BarCount = Bars;
return(0);
}
//+------------------------------------------------------------------+
Would help to actually see code or failing that please right click [and copy so can paste into your post] the compiler error text you are talking about ie, what variable are you talking about... ;)
Not enough info - have no idea just what your HASmoothed uses regards: parameters and index buffers
For instance, I found on my hard drive an HA source file and it had:
//---- extern color color1 = Red; extern color color2 = White; extern color color3 = Red; extern color color4 = White; //---- buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; double ExtMapBuffer3[]; double ExtMapBuffer4[];
EG, if wanted the value from index buffer2 at ExtMapBuffer2[Current] then:
double HAS2 = iCustom(NULL, 0, "someHA", Red, White, Red, White, 1, Current + 0); //where: 1=index buffer2; and I have no idea about variable contents of Current identifier.
notice that afaik, all parameters must be listed: as in above there are 4 and must be listed left to right as declared in source file (top..bottom): color1,color2,...
and numbering of indexbuffers is from 0..7 so ExtMapBuffer2 is actually 1
also, + 0 not needed, is redundant.
double HAS2 = iCustom(NULL, 0, "Heikin_Ashi_Smoothed",True, Red, 2, Current+ 0);
double HAS3 = iCustom(NULL, 0, "Heikin_Ashi_Smoothed",True, RoyalBlue, 3, Current + 0);
double iCustom( | string symbol, int timeframe, string name, ..., int mode, int shift) |
symbol | - | Symbol the data of which should be used to calculate indicator. NULL means current symbol. |
timeframe | - | Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. |
name | - | Custom indicator compiled program name. |
... | - | Parameters set (if necessary). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator. |
mode | - | Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions. |
shift | - | Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). |
This gives me some idea of where to start. The more I try to do the more confused I seem to become.
I thought I had an EA working. It takes way too many trades and gets out when it should stay in the market. What I was trying to do was to take an entry long when the price opened over the testing level of the Gann HiLo Activator & the
Bulls from buffer 2 was > the Bears from buffer 3. The reverse was a sell and if either indicator reversed against my position this was an exit. Here is what I was trying and I do not know why it does not work at all. #define SIGNAL_NONE 0
#define SIGNAL_BUY 1
#define SIGNAL_SELL 2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4
#property copyright "Keith Bunge"
extern string Remark1 = "== Main Settings ==";
extern int MagicNumber = 0;
extern bool SignalMail = False;
extern bool EachTickMode = True;
extern double Lots = 0.1;
extern int Slippage = 3;
extern bool UseStopLoss = False;
extern int StopLoss = 30;
extern bool UseTakeProfit = false;
extern int TakeProfit = 60;
extern bool UseTrailingStop = false;
extern int TrailingStop = 30;
extern bool MoveStopOnce = False;
extern int MoveStopWhenPrice = 50;
extern int MoveStopTo = 1;
int BarCount;
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init() {
BarCount = Bars;
if (EachTickMode) Current = 0; else Current = 1;
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int Order = SIGNAL_NONE;
int Total, Ticket;
double StopLossLevel, TakeProfitLevel;
if (EachTickMode && Bars != BarCount) TickCheck = False;
Total = OrdersTotal();
Order = SIGNAL_NONE;
//+------------------------------------------------------------------+
//| Variable Begin |
//+------------------------------------------------------------------+
double FastMain = iCustom(NULL, 0, "AbsoluteStrenghtHisto_v2", "*** Strong Trend Line *** *** Indicator Settings ***", True, 2, Current + 0);
double FastSignal = iCustom(NULL, 0, "AbsoluteStrenghtHisto_v2", "*** Weak Trend Line *** *** Indicator Settings ***", True, 3, Current + 0);
double FastMain1 = iCustom(NULL, 0, "AbsoluteStrenghtHisto_v2", "*** Strong Trend Line *** *** Indicator Settings ***", True, 2, Current + 1);
double FastSignal1 = iCustom(NULL, 0, "AbsoluteStrenghtHisto_v2", "*** Weak Trend Line *** *** Indicator Settings ***", True, 3, Current + 1);
double SlowMain = iCustom(NULL, 0, "FX5_MACD_Divergence_V1.1", "*** MACD Settings ***", 12, 26, 9, "*** Indicator Settings ***", True, True, True, 2, Current + 0);
double SlowSignal = iCustom(NULL, 0, "FX5_MACD_Divergence_V1.1", "*** MACD Settings ***", 12, 26, 9, "*** Indicator Settings ***", True, True, True, 3, Current + 0);
double SlowMain1 = iCustom(NULL, 0, "FX5_MACD_Divergence_V1.1", "*** MACD Settings ***", 12, 26, 9, "*** Indicator Settings ***", True, True, True, 2, Current + 1);
double SlowSignal1 = iCustom(NULL, 0, "FX5_MACD_Divergence_V1.1", "*** MACD Settings ***", 12, 26, 9, "*** Indicator Settings ***", True, True, True, 3, Current + 1);
//+------------------------------------------------------------------+
//| Variable End |
//+------------------------------------------------------------------+
//Check position
bool IsTrade = False;
for (int i = 0; i < Total; i ++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
IsTrade = True;
if(OrderType() == OP_BUY) {
//Close
//+------------------------------------------------------------------+
//| Signal Begin(Exit Buy) |
//+------------------------------------------------------------------+
if ((FastMain < FastSignal && FastMain1 >= FastSignal1) || (SlowMain < SlowSignal && SlowMain1 >= SlowSignal1)) Order = SIGNAL_CLOSEBUY;
//+------------------------------------------------------------------+
//| Signal End(Exit Buy) |
//+------------------------------------------------------------------+
if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
//MoveOnce
if(MoveStopOnce && MoveStopWhenPrice > 0) {
if(Bid - OrderOpenPrice() >= Point * MoveStopWhenPrice) {
if(OrderStopLoss() < OrderOpenPrice() + Point * MoveStopTo) {
OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() + Point * MoveStopTo, OrderTakeProfit(), 0, Red);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
//Trailing stop
if(UseTrailingStop && TrailingStop > 0) {
if(Bid - OrderOpenPrice() > Point * TrailingStop) {
if(OrderStopLoss() < Bid - Point * TrailingStop) {
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
} else {
//Close
//+------------------------------------------------------------------+
//| Signal Begin(Exit Sell) |
//+------------------------------------------------------------------+
if ((FastMain > FastSignal && FastMain1 <= FastSignal1) || (SlowMain > SlowSignal && SlowMain1 <= SlowSignal1)) Order = SIGNAL_CLOSESELL;
//+------------------------------------------------------------------+
//| Signal End(Exit Sell) |
//+------------------------------------------------------------------+
if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
//MoveOnce
if(MoveStopOnce && MoveStopWhenPrice > 0) {
if(OrderOpenPrice() - Ask >= Point * MoveStopWhenPrice) {
if(OrderStopLoss() > OrderOpenPrice() - Point * MoveStopTo) {
OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() - Point * MoveStopTo, OrderTakeProfit(), 0, Red);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
continue;
}
}
}
}
//+------------------------------------------------------------------+
//| Signal Begin(Entry) |
//+------------------------------------------------------------------+
if ((FastMain > FastSignal && SlowMain > SlowSignal && (FastMain1 <= FastSignal1 || SlowMain1 <= SlowSignal1)) Order = SIGNAL_BUY;
if ((FastMain < FastSignal && SlowMain < SlowSignal && (FastMain1 >= FastSignal1 || SlowMain1 >= SlowSignal1)) Order = SIGNAL_SELL;
//+------------------------------------------------------------------+
//| Signal End |
//+------------------------------------------------------------------+
//Buy
if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;
Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("BUY order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
} else {
Print("Error opening BUY order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}
//Sell
if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;
Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("SELL order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
} else {
Print("Error opening SELL order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}
if (!EachTickMode) BarCount = Bars;
return(0);
}
//+------------------------------------------------------------------+
I am making the assumption that an EA will work on any time frame that it is attached to and read the signals from the time frame of the chart that the chart is set at. I have seen some EA's that tell it to only read from certain time frames but I think this assumption is correct. I have been wrong about so much I thought I might put my thoughts down to get confirmation or correction.
I am making the assumption that an EA will work on any time frame that it is attached to and read the signals from the time frame of the chart that the chart is set at. I have seen some EA's that tell it to only read from certain time frames but I think this assumption is correct. I have been wrong about so much I thought I might put my thoughts down to get confirmation or correction.
correct. EA defaults to the environment of the chart it is run on.
yes. An EA can be selective in what time frame, symbol, clock time,etc. it will look for trades... Totally under programmers control.
When you have spare moment please help me to help you... thanks!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use