
Você está perdendo oportunidades de negociação:
- Aplicativos de negociação gratuitos
- 8 000+ sinais para cópia
- Notícias econômicas para análise dos mercados financeiros
Registro
Login
Você concorda com a política do site e com os termos de uso
Se você não tem uma conta, por favor registre-se
Ei, codificadores!
Aaragorn e eu temos trabalhado nisto ultimamente.
extern bool SignalMail = False;
extern bool EachTickMode = False;
extern double Lots = 0.1;
extern int Slippage = 3;
extern bool StopLossMode = False;
extern int StopLoss = 5;
extern bool TakeProfitMode = True;
extern int TakeProfit = 50;
extern bool TrailingStopMode = False;
extern int TrailingStop = 5;
extern int MaxOpenTrade = 1;
extern int Shift = 2;
extern double Slope = 2;
extern int EnterEMA = 38;
extern int ExitEMA = 1500;
#define SIGNAL_NONE 0
#define SIGNAL_BUY 1
#define SIGNAL_SELL 2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4
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 Buy1_1 = iMA(NULL, 0, EnterEMA, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double Buy1_2 = iClose(NULL, 0, Current + 0);
double Buy2_1 = iMA(NULL, 0, EnterEMA, 0, MODE_EMA, PRICE_CLOSE, Current + Shift);
double Buy2_2 = iClose(NULL, 0, Current + Shift);
double Sell1_1 = iMA(NULL, 0, EnterEMA, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double Sell1_2 = iClose(NULL, 0, Current + 0);
double Sell2_1 = iMA(NULL, 0, EnterEMA, 0, MODE_EMA, PRICE_CLOSE, Current + Shift);
double Sell2_2 = iClose(NULL, 0, Current + Shift);
double CloseBuy1_1 = iClose(NULL, 0, Current + 0);
double CloseBuy1_2 = iMA(NULL, 0, ExitEMA, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double CloseSell1_1 = iClose(NULL, 0, Current + 0);
double CloseSell1_2 = iMA(NULL, 0, ExitEMA, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
//+------------------------------------------------------------------+
//| Variable End |
//+------------------------------------------------------------------+
bool IsTrade = False;
for (int i = 0; i < Total; i ++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
IsTrade = True;
if(OrderType() == OP_BUY) {
//+------------------------------------------------------------------+
//| Signal Begin(Exit Buy) |
//+------------------------------------------------------------------+
if (Sell1_1 < CloseBuy1_2) 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;
}
if(TrailingStopMode && 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 {
//+------------------------------------------------------------------+
//| Signal Begin(Exit Sell) |
//+------------------------------------------------------------------+
if (Sell1_1 > CloseBuy1_2) 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;
}
if(TrailingStopMode && TrailingStop > 0) {
if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Signal Begin(Entry logics) |
//+------------------------------------------------------------------+
if (Buy1_1 < Buy1_2 && Buy2_1 Buy2_1*/) Order = SIGNAL_BUY;
if (Sell1_1 > Sell1_2 && Sell2_1 > Sell2_2/* && Sell1_1 + Slope*Point < Sell2_1*/) Order = SIGNAL_SELL;
//+------------------------------------------------------------------+
//| Signal End |
//+------------------------------------------------------------------+
if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
IsTrade = False;//---allows multiple orders to open
if(!IsTrade) {
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if (StopLossMode) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
if (TakeProfitMode) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;
if(OrdersTotal() < MaxOpenTrade)
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);
}
}
if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
IsTrade = False;//---allows multiple orders to open
if(!IsTrade) {
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if (StopLossMode) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
if (TakeProfitMode) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;
if(OrdersTotal() < MaxOpenTrade)
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);
}
//+------------------------------------------------------------------+"Shift" é quantos períodos você olha para trás, e "Slope" é quantos navios a "EnterEMA" subiu no "Shift". Ainda estamos aperfeiçoando a estratégia, e eu estava pensando se você poderia me ajudar com algo.
isto é para dar algum contexto antes de me restringir ao código sobre o qual tenho uma pergunta...
#property link "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"
extern int MagicNumber = 0;
extern bool SignalMail = False;
extern bool EachTickMode = False;
extern double Lots = 0.35;
extern int Slippage = 3;
extern bool StopLossMode = False;
extern int StopLoss = 5;
extern bool TakeProfitMode = True;
extern int TakeProfit = 42;
extern bool TrailingStopMode = False;
extern int TrailingStop = 10;
extern int MaxOpenTrade = 1;
extern int Shift = 3;
//extern double Slope = 2;
extern int EntLongEMA = 46;
extern int EntShortEMA = 1;
extern int ExitEMA = 52;
extern int TrendEMA = 150;
//+-----------close based on not triggering trailing stop in allotted time----------------+
extern int MonitorInMinutes = 60; // minutes after open to check state of trade
extern int ThresholdMove = 1; // if after that time we don't have +'x' pips we will exit
extern int MinsMultiplier = 90; // multiplies the MonitorInMinutes to make minutes (if 'x'=60) into hours
#define SIGNAL_NONE 0
#define SIGNAL_BUY 1
#define SIGNAL_SELL 2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4
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 Buy1_1 = iMA(NULL, 0, EntLongEMA, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double Buy1_2 = iMA(NULL, 0, EntShortEMA, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double Buy2_1 = iMA(NULL, 0, EntLongEMA, 0, MODE_EMA, PRICE_CLOSE, Current + Shift);
double Buy2_2 = iMA(NULL, 0, EntShortEMA, 0, MODE_EMA, PRICE_CLOSE, Current + Shift);
double Sell1_1 = iMA(NULL, 0, EntLongEMA, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double Sell1_2 = iMA(NULL, 0, EntShortEMA, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double Sell2_1 = iMA(NULL, 0, EntLongEMA, 0, MODE_EMA, PRICE_CLOSE, Current + Shift);
double Sell2_2 = iMA(NULL, 0, EntShortEMA, 0, MODE_EMA, PRICE_CLOSE, Current + Shift);
double CloseBuy1_1 = iMA(NULL, 0, EntShortEMA, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double CloseBuy1_2 = iMA(NULL, 0, ExitEMA, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double CloseSell1_1 = iMA(NULL, 0, EntShortEMA, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double CloseSell1_2 = iMA(NULL, 0, ExitEMA, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double C_trendsetter = iMA(NULL, 0, TrendEMA, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double S_trendsetter = iMA(NULL, 0, TrendEMA, 0, MODE_EMA, PRICE_CLOSE, Current + Shift);
//+------------------------------------------------------------------+
//| 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()) {
IsTrade = True;
if(OrderType() == OP_BUY) {
//Close
//+------------------------------------------------------------------+
//| Signal Begin(Exit Buy)Closing logic for long positions |
//+------------------------------------------------------------------+
// if (Buy1_1 <= C_trendsetter) Order = SIGNAL_CLOSEBUY;
if (Buy1_1 <= C_trendsetter) StopLossMode = True;
if (Buy1_1 <= CloseBuy1_2) CloseOrder();
if (Buy1_1 <= CloseBuy1_2) TrailingStopMode = True;
//+------------------------------------------------------------------+
//| 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;
}
//Trailing stop
if(TrailingStopMode && 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;
TrailingStopMode = False; //resets mode after each order
StopLossMode = False; //resets mode after each order
continue;
}
}
}
} else {
//Close
//+------------------------------------------------------------------+
//| Signal Begin(Exit Sell)Closing logic for short positions |
//+------------------------------------------------------------------+
// if (Buy1_1 >= C_trendsetter) Order = SIGNAL_CLOSEBUY;
if (Buy1_1 >= C_trendsetter) StopLossMode = True;
if (Sell1_1 >= CloseSell1_2) CloseOrder();
if (Sell1_1 >= CloseSell1_2) TrailingStopMode = True;
//+------------------------------------------------------------------+
//| 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;
}
//Trailing stop
if(TrailingStopMode && TrailingStop > 0) {
if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
if (!EachTickMode) BarCount = Bars;
TrailingStopMode = False; //resets mode after each order
StopLossMode = False; //resets mode after each order
continue;
}
}
}
}
}
}[/PHP]
I am working on the exit logics... This is the buy.closing...
//| Signal Begin(Exit Buy)Closing logic for long positions |
//+------------------------------------------------------------------+
if (Buy1_1 <= C_trendsetter) Order = SIGNAL_CLOSEBUY;
// if (Buy1_1 <= C_trendsetter) StopLossMode = True;
if (Buy1_1 <= CloseBuy1_2) CloseOrder();
if (Buy1_1 <= CloseBuy1_2) TrailingStopMode = True;When I turn on the close buy condition it does in fact close the trade.
see attached.
[PHP]//+------------------------------------------------------------------+
//| Signal Begin(Exit Buy)Closing logic for long positions |
//+------------------------------------------------------------------+
// if (Buy1_1 <= C_trendsetter) Order = SIGNAL_CLOSEBUY;
if (Buy1_1 <= C_trendsetter) StopLossMode = True;
if (Buy1_1 <= CloseBuy1_2) CloseOrder();
if (Buy1_1 <= CloseBuy1_2) TrailingStopMode = True;se a parada de perda acionou deveria ter fechado logo em seguida, mas não, ainda assim a parada de fuga obviamente acionou, ver anexo...
Ainda não fazendo o que lhe digo para fazer...
Fechou na primeira troca...mas não na segunda troca...ver anexo.
if (Buy1_1 + StopLoss*Point <= C_trendsetter) Order = SIGNAL_CLOSEBUY;
isto parece funcionar.
encontrou o bug...
este deve ser
if (Buy1_1 + StopLoss*Point <= C_trendsetter) Order = SIGNAL_CLOSESELL;
para os calções...
Eu copio e colo tanto que perdi o sinal do pedido...oy.
if (Buy1_1 + StopLoss*Point <= C_trendsetter) Order = SIGNAL_CLOSEBUY;
deve ser
if (Buy1_1 + StopLoss*Point <= C_trendsetter) Order = SIGNAL_CLOSESELL;
Perguntas sobre cores
Como faço para que as linhas médias móveis sejam a cor que eu especifico quando abre no gráfico de teste de estratégia?
Como faço para que as setas apareçam maiores quando abro o gráfico do testador de estratégia?
você acha que é possível ter envelopes médios móveis que se projetam para o futuro em linha reta?
você acha que é possível ter envelopes médios móveis que se projetam para o futuro em linha reta?
As médiasmóveis são determinadas pela média dos últimos "x" períodos,
por exemplo, se você aplicar a média móvel ao fechamento, um período fecha a 1,3417, e o próximo é 5 pips mais alto, e os próximos 5 mais altos, e etc., uma média móvel seria "média" para chegar a um valor atual.
e como o preço está sempre mudando, apenas as médias móveis que olham para trás por mais de 100 pips ou mais, olham perto da reta na maior parte do tempo
em resposta à sua pergunta, se for possível, por favor me avise! (lol)
Olá, estou trabalhando em um EA com o qual estou tentando fazer uma cruzada de preços.
Como sei se ela cruzou?
se eu sei se Ask>iCustom() então ele coloca em ordem a qualquer momento que estiver acima
se eu faço se perguntar=iCustom() então ele perde a compra porque o faz por minuto
no livro de ofertas que eu faria se perguntasse[-1] =iCustom, mas eu não posso fazer isso aqui como Ask e Bid não têm história
gráficos adicionais
oi,
isto é provavelmente irrelevante para este tópico, mas eu queria saber como adicionar gráficos extras para metatrader 4...como prata, audnzd, nzdusd, platanium etc. Alguém me deu este anexo uma vez para copiar cola na pasta do metatrader para obter estes gráficos, mas parece que eu o perdi, então alguém pode me ajudar aqui.
thnx
kev