How to code? - page 149

 

Nonlagzigzag signal problem

Hi kevin07,

The alerts for nonlagzigzag are working but they do not correspond with a zigzag line. I have received several alerts but the zigzag line has not painted. Also, when I first load the indicator it gives an alert. Can you look at the code and see if you can spot the problem? The email alert works great also, thanks for including it. Anything you can do will be very much appreciated.

Best regards, Tom

 

nonlagzigzag

Hello tk748, The initial alert that poped up when you loaded the indi tells the current direction of trade since the last highest high or lowest low (which may have occured several candles back). Sorry to hear that intermediate alerts go out prior to the next line being drawn. The IF statement for the alert could have an additional filter to check that CurrentDirection != PreviousDirection so that additional alerts don't pop up until the next line is drawn. (I'm involved in finishing my EA and cannot tackle that for you at this time.) During the day, I have to work. During the night, I have to sleep. Without an EA, I won't get many (any) trades. My priority is to use a zigzag or volitility indi as a filter to prevent some unprofitable trades from opening.

If I find how to add that additional code in the process, I'll let you know.

Best Wishes, kevin07

 

Straddle Script

I got this script but would love to have the option of setting a timer to have it trade the London open... how hard would it be to add this and could you point me in the right direct or show me the code to do it?

As always... I appreciate your help!!

#include

#include

#define LOOK_TO_BUY 1

#define LOOK_TO_SELL 2

extern int Magic_Number = 412625; // set this to a unique number if you intend to use the script simulataneously across many charts on the same account.

extern int UserDefinedSpread = 0; // set this to 0 if you want to use market spread. valid value is >= 0

extern double LotSize = 0.1;

extern int Slippage = 3;

extern int StopLoss = 25; // If you set StopLoss to 0, no stop loss level will be placed.

extern int TakeProfit = 0; // If you set TakeProfit to 0, no stop loss level will be placed.

extern bool OneCancelsOther = true; // This determines if you want the script to stay running and track, then delete the opposite pending order when an order has executed.

extern int NumOfCandles = 3; // This determines how many previous candles you want the EA to look for the High Lows. (buy and sell prices). valid value is > 0

extern int PositionalMarginPips = 40; // The distance excluding spread from the high lows for the opening prices. valid value is >= 0

extern int intervalseconds = 1.0; //The time interval for the script to check your trades. allows fractional seconds.

double BuyPrice = 0;

double SellPrice = 0;

int CustomSpread = 0;

bool KeepRunning = true;

int ticketToDelete = 0;

void GetPrices()

{

double HighestHigh = High[1];

if (NumOfCandles > 1)

{

for (int i=2; i<=NumOfCandles; i++)

{

if (High > HighestHigh)

{

HighestHigh = High;

}

}

}

BuyPrice = HighestHigh + (PositionalMarginPips * Point);

BuyPrice = NormalizeDouble(BuyPrice,Digits);

double LowestLow = Low[1];

if (NumOfCandles > 1)

{

for (i=2; i<=NumOfCandles; i++)

{

if (Low < LowestLow)

{

LowestLow = Low;

}

}

}

SellPrice = LowestLow - (PositionalMarginPips * Point);

BuyPrice = NormalizeDouble(BuyPrice,Digits);

}

void PlaceTrades()

{

double TakeProfitPrice, StopLossPrice;

if (TakeProfit==0)

{

TakeProfitPrice = 0;

}

else

{

TakeProfitPrice = BuyPrice + (TakeProfit * Point);

TakeProfitPrice = NormalizeDouble(TakeProfitPrice,Digits);

}

if (StopLoss == 0)

{

StopLossPrice = 0;

}

else

{

StopLossPrice = BuyPrice - (StopLoss * Point);

StopLossPrice = NormalizeDouble(StopLossPrice,Digits);

}

SendOrders (LOOK_TO_BUY, LotSize, BuyPrice, Slippage, StopLossPrice, TakeProfitPrice, "Straddle Buy", 0);

if (TakeProfit==0)

{

TakeProfitPrice = 0;

}

else

{

TakeProfitPrice = SellPrice - (TakeProfit * Point);

TakeProfitPrice = NormalizeDouble(TakeProfitPrice,Digits);

}

if (StopLoss == 0)

{

StopLossPrice = 0;

}

else

{

StopLossPrice = SellPrice + (StopLoss * Point);

StopLossPrice = NormalizeDouble(StopLossPrice,Digits);

}

SendOrders (LOOK_TO_SELL, LotSize, SellPrice, Slippage, StopLossPrice, TakeProfitPrice, "Straddle Sell", 0);

}

void SendOrders (int BuyOrSell, double LotSize, double PriceToOpen, double Slippage, double SL_Price, double TP_Price, string comments, datetime ExpirationTime)

{

int PositionType, ticket, errorType;

if (BuyOrSell == LOOK_TO_BUY)

{

if (PriceToOpen > Ask)

{

PositionType = OP_BUYSTOP;

}

if (PriceToOpen < Ask)

{

PositionType = OP_BUYLIMIT;

}

Print("Bid: "+Bid+" Ask: "+Ask+" | Opening Buy Order: "+Symbol()+", "+PositionType+", "+LotSize+", "+PriceToOpen+", "+Slippage+", "+SL_Price+", "+TP_Price+", "+comments+", "+Magic_Number+", "+ExpirationTime+", Green");

ticket=OrderSend(Symbol(),PositionType,LotSize,PriceToOpen,Slippage,SL_Price,TP_Price,comments,Magic_Number,ExpirationTime,CLR_NONE);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))

{

Print("BUY order opened : ",OrderOpenPrice());

}

}

else

{

errorType = GetLastError();

Print("Error opening BUY order : ", ErrorDescription(errorType));

}

}

if (BuyOrSell == LOOK_TO_SELL)

{

if (PriceToOpen < Bid)

{

PositionType = OP_SELLSTOP;

}

if (PriceToOpen > Bid)

{

PositionType = OP_SELLLIMIT;

}

Print("Bid: "+Bid+" Ask: "+Ask+" | Opening Sell Order: "+Symbol()+", "+PositionType+", "+LotSize+", "+PriceToOpen+", "+Slippage+", "+SL_Price+", "+TP_Price+", "+comments+", "+Magic_Number+", "+ExpirationTime+", Red");

ticket=OrderSend(Symbol(),PositionType,LotSize,PriceToOpen,Slippage,SL_Price,TP_Price,comments,Magic_Number,ExpirationTime,CLR_NONE);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))

{

Print("Sell order opened : ",OrderOpenPrice());

}

}

else

{

errorType = GetLastError();

Print("Error opening SELL order : ", ErrorDescription(errorType));

}

}

}

void GetSpread()

{

if (UserDefinedSpread <= 0)

{

CustomSpread = MarketInfo(Symbol(),MODE_SPREAD);

}

else

{

CustomSpread = UserDefinedSpread;

}

}

int GetNumberOfPending()

{

int count = 0;

int total = OrdersTotal();

if (total > 0)

{

for(int cnt=0;cnt<total;cnt++)

{

if(OrderSelect(cnt,SELECT_BY_POS))

{

if(OrderSymbol()==Symbol() && OrderMagicNumber() == Magic_Number)

{

if(OrderType() != OP_BUY && OrderType() != OP_SELL)

{

ticketToDelete = OrderTicket();

count++;

}

}

}

}

}

return (count);

}

void ManageTrades()

{

// If there's only one pending trade left, assume the other one is opened.

// So Delete this one.

if (GetNumberOfPending() == 1)

{

if (OrderDelete(ticketToDelete))

{

KeepRunning = false;

Alert ("Straddle script has ended");

}

}

}

//+------------------------------------------------------------------+

//| script program start function |

//+------------------------------------------------------------------+

int start()

{

//----

GetSpread();

GetPrices();

PlaceTrades();

Alert ("Pending Trades Placed. Please Wait...");

int intervalMilliseconds = intervalseconds * 1000;

while (KeepRunning && OneCancelsOther)

{

Sleep(intervalMilliseconds);

ManageTrades();

}

//----

return(0);

}

//+------------------------------------------------------------------+

 

nonlagzigzag alert

Hi kevin07,

Thanks for the work you did on this indicator. Perhaps during your EA coding you will have an idea about how to make the signals appear at the proper time. In the meantime maybe someone else here will have time to solve the problem. Good luck with your EA.

Regards,

Tom

 

Please help me to add matigale code

I have just mde this EA using this site: Expert Advisor Builder for MetaTrader 4 basing on simple rules to trade.

You can try this EA to see the result. Please set SL = 100, TP = 300 , trailing stop = 70 and run it on EUR/USD H4.

Would you please kindly help me put martigale to trade this system:

Use an amount so that 100 pips = 2% of account balance

If the trade n-1 is lost, double amount of trade n until closing position with profit.

Thank you very much!

Files:
 
vinafx:
I have just mde this EA using this site: Expert Advisor Builder for MetaTrader 4 basing on simple rules to trade.

You can try this EA to see the result. Please set SL = 100, TP = 300 , trailing stop = 70 and run it on EUR/USD H4.

Would you please kindly help me put martigale to trade this system:

Use an amount so that 100 pips = 2% of account balance

If the trade n-1 is lost, double amount of trade n until closing position with profit.

Thank you very much!

It worths to spend a little time, friends! This is the result of trading without martigale code. Initial deposit: 10000; 1 lot per trade. SL = 100; TP = 300; Trailing ST: 70; EUR/USD H4.

Files:
 

how do you simplify this code?

the difference between a and b <= c then trade = true, else false..

so far this is what i have made if anyone can show me a shorter way to code this..

if ( a >= b)

{

if (a - b <= c ) trade = true;

if (a - b > c) trade = false;

}

if ( a < b)

{

if (b - a <= c ) trade = true;

if (b - a > c) trade = false;

}

 

try this (I am assuming that c is >= 0)

trade = (MathAbs(a-b) <= c);

regards

mladen

fercan:
how do you simplify this code?

the difference between a and b <= c then trade = true, else false..

so far this is what i have made if anyone can show me a shorter way to code this..

if ( a >= b)

{

if (a - b <= c ) trade = true;

if (a - b > c) trade = false;

}

if ( a < b)

{

if (b - a <= c ) trade = true;

if (b - a > c) trade = false;

}
 
mladen:
try this (I am assuming that c is >= 0)
trade = (MathAbs(a-b) <= c);

regards

mladen

thank you.. i was looking for something like this before.. thanks..

 

test NonLagZigZag_Signal_v2 alerts

tk748:
Hi kevin07,

Thanks ...Perhaps ... you will have an idea about how to make the signals appear at the proper time...

Regards,

Tom

Hey Tom,

I was able to get back to this ZigZag indi and filter out intermediate alerts. I'm sending this immediately and have not tested it. Please let me know if you find any alert related problems with it.

Thanks

kevin07

Reason: