Results 1 to 11 of 11

Thread: Need Help

  1. #1

    Default Need Help

    Dear Sir,

    Please find attached Script which gives an error (script you are executing taking longer time than expected......) some time which I have shown in screen shot attached here with the script. can you please advise me proper rectification for the same.

    Thanks,
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Untitled.jpg 
Views:	5 
Size:	23.1 KB 
ID:	585  
    Attached Files Attached Files

  2. #2
    Administrator Rawan-HS's Avatar
    Join Date
    Apr 2015
    Posts
    354

    Default

    Dear BGT

    I will check it when market open but you have to make sure that no infinite loop which caused this error ,
    Note : there is another error appeared (Overflow error ) when there is no trade opened just make a validation when the trade count is more than zero .

  3. #3

    Default

    Hi Any update on the issue ??

    Quote Originally Posted by Rawan-HS View Post
    Dear BGT

    I will check it when market open but you have to make sure that no infinite loop which caused this error ,
    Note : there is another error appeared (Overflow error ) when there is no trade opened just make a validation when the trade count is more than zero .

  4. #4
    Administrator Rawan-HS's Avatar
    Join Date
    Apr 2015
    Posts
    354

    Default

    Dear BGT

    I have tested the script form my side and the error that you attached not appeared , as I said before make sure that no infinite loop which caused this error ,
    Note : there is another error appeared (Overflow error ) when there is no trade opened just make a validation when the trade count is more than zero .

  5. #5

    Default

    Hi when I submitted it to your developer they are giving me following comments


    I have tested it when you attach the script the bellow bugs will appear :

    1.invaild period for SMA indicator

    2.subscript out of range

    3. and sometimes it will be stuck in an infinite loop and invalid amount errors will many times




    whereas I am not getting any such error at my end. Cam you please look in to it and guide me how to resolve this issue.

    Especially the issue of infinite loop.


    Hope to hear from you soon.

    Thanks

  6. #6
    Administrator Rawan-HS's Avatar
    Join Date
    Apr 2015
    Posts
    354

    Default

    Dear BGT

    About the infinite loop that happened on the script make sure that you are passing a valid amount ,
    I found that your amount depended on account balance so if the balance is larger than the maximum amount open a trade on a value of the maximum amount and must be one of multiplication of the minimum amount
    Last edited by Rawan-HS; 11-18-2019 at 02:04 PM.

  7. #7

    Default

    Quote Originally Posted by Rawan-HS View Post
    Dear BGT

    About the infinite loop that happened on the script make sure that you are passing a valid amount ,
    I found that your amount depended on account balance so if the balance is larger than the maximum amount open a trade on a value of the maximum amount and must be one of multiplication of the minimum amount

    hi can you guide me in details. I am not able to understand it. It would be a great help if you could explain in more details.

    Thanks,

    BGT

  8. #8
    Administrator Rawan-HS's Avatar
    Join Date
    Apr 2015
    Posts
    354

    Default

    Dear BGT

    As I told you at your script you are depending on the balance value to set the amount value so if the value of amount is larger than the maximum amount or not one of Multiples for the minimum amount ,that will cause the invalid amount error . For example the Minimum amount = 5 so you can't take any trade on amount not multiples of 5 (You can take trade on 5,10,15,... etc ) and you can't open a trade on amount larger than the maximum amount

  9. #9

    Default

    We have already added
    SymbolInfoDouble cstr(Symbol), SYMBOL_VOLUME_MIN,minlot
    SymbolInfoDouble cstr(Symbol), SYMBOL_VOLUME_MAX,maxlot
    accBalance=AccountInfoDouble(ACCOUNT_BALANCE)
    M=Round(((accBalance * 0.005 * Z) / (0.1 * stoploss)),2) ' x% risk per trade
    'AlertMessage("M= " & M & "Minlot= " & minlot & "Maxlot= " & maxlot )
    AlertMessage("After Lot")
    AlertMessage("accBalance = " & accBalance & "M= " & M)
    if M <> 0 Then
    M = CLng(M/minlot) * minlot
    end if

    if(M<minlot) then
    M=minlot
    end if
    if(M>maxlot) then
    M=maxlot
    end if

    if (M<1) then M=1 end If

  10. #10
    Administrator Rawan-HS's Avatar
    Join Date
    Apr 2015
    Posts
    354

    Default

    Dear BGT

    I have checked the code from my side and everything was fine but check from your side that you are not change the value of the amount when passing it to NewMarketOrder method .

  11. #11

    Default

    Please check following complete code and suggest the solution



    Const buffer=0
    Const stoploss=20
    Const takeprofit=350
    Const filter1=50
    Const ma_value=218
    Const Z=2

    Dim max_account_balance
    Dim max_spread
    Dim price_above

    Dim M 'risk
    Dim trade_ok
    Dim ticket1

    Dim entryprice
    '++++ These are adjusted for 5 digit brokers.
    Dim pips2points ' slippage 3 pips 3=points 30=points
    Dim pips2dbl 'Stoploss 15 pips 0.0015 0.00150
    Dim Digitspips 'DoubleToStr(dbl/pips2dbl, Digits.pips)


    ''' <summary>
    ''' The main function is the entry point for any Script program
    ''' </summary>

    Public Sub main()
    ''''TODO: Script program start method
    max_account_balance=0
    max_spread=4
    price_above=false
    M=1
    trade_ok=true
    ticket1=-1
    entryprice=0


    'dim tt
    'tt = PositionTotal()
    'if PositionTotal() > 0 Then
    call EURUSD_Trader()
    'end if

    End Sub

    public Sub EURUSD_Trader()
    dim Spread,ticket,PositionTicket,symbol,Bid,Ask,piploc ,Point,accBalance,result
    dim minlot,maxlot,Atr
    dim HighAry(),LowAry(),OpenAry(),CloseAry(),tempAry(), arrAtr()
    dim highVal,lowVal,closeVal,SMA_10day
    dim NewOrderFlag
    symbol=ChartSymbol(0)
    CopyHigh 0, 1, Bars (0), HighAry
    CopyLow 0, 1, Bars (0), LowAry
    copyOpen 0,1,Bars(0),OpenAry
    CopyClose 0, 1, Bars (0), CloseAry

    SimpleMovingAverageOnArray HighAry,CInt (ma_value), tempAry
    highVal=tempAry(Bars(0))
    SimpleMovingAverageOnArray LowAry,CInt (ma_value), tempAry
    lowVal=tempAry(Bars(0))
    SimpleMovingAverageOnArray CloseAry,CInt (ma_value), tempAry
    closeVal=tempAry(Bars(0))

    SMA_10day = (highVal + lowVal + closeVal) / 3 ' simple ma_value day moving average value

    dim arrHigh(),arrLow(),arrOpen(),arrclose()

    AverageTrueRangeOnArray OpenAry, HighAry, LowAry, CloseAry, arrAtr
    Atr=arrAtr(Bars(0))
    '-----risk management (X * (1-0.005*Z)^lose-trades= how much left) - http://mathhelpforum.com/calculus/21...tml#post767362
    SymbolInfoDouble cstr(Symbol), SYMBOL_VOLUME_MIN,minlot
    SymbolInfoDouble cstr(Symbol), SYMBOL_VOLUME_MAX,maxlot
    accBalance=AccountInfoDouble(ACCOUNT_BALANCE)
    M=Round(((accBalance * 0.005 * Z) / (0.1 * stoploss)),2) ' x% risk per trade

    if M <> 0 Then
    M = CLng(M/minlot) * minlot
    end if

    if(M<minlot) then
    M=minlot
    end if
    if(M>maxlot) then
    M=maxlot
    end if

    if (M<1) then M=1 end If

    if (accBalance > max_account_balance) Then
    max_account_balance = accBalance

    end If
    '-----end of risk

    '---------------- open new trades
    ' --- * short trade
    SymbolInfoDouble cstr(symbol),SYMBOL_ASK,Ask
    SymbolInfoDouble cstr(symbol),SYMBOL_BID,Bid

    if (trade_ok) Then
    if ( ( Bid- SMA_10day < buffer* pips2dbl ) and (price_above) and (ATR<40*pips2dbl) ) Then
    ticket1 = -1


    NewOrderFlag = false
    While (Ask-Bid < max_spread* pips2dbl and NewOrderFlag = false) 'spread < 4

    ticket1 = NewMarketOrder (TRADE_ACTION_SELL,cstr(symbol),cdbl(0.01*M))


    if (ticket1 = true) Then

    NewOrderFlag = true
    entryprice = Bid

    end If

    wend
    trade_ok=false
    '--- * end of short trade
    else
    'long trade
    if ( ( SMA_10day - Ask < buffer* pips2dbl ) and (NOT price_above) and (ATR<40*pips2dbl)) Then

    ticket1=-1

    NewOrderFlag = false
    While (Ask-Bid<max_spread* pips2dbl and NewOrderFlag = false) 'spread < 4
    ticket1 = NewMarketOrder (TRADE_ACTION_BUY,cstr(symbol),cdbl(0.01*M))

    if (ticket1 = true) Then

    NewOrderFlag = TRUE

    entryprice=Ask

    end If
    'exit While
    wend
    trade_ok=false
    end If

    end If
    '--- * end of long trade
    end If
    '---- end of open new trades

    '-----x pip noice filter

    if (not trade_ok) Then

    if (price_above) then '-- price currently above

    if (Bid < entryprice - filter1* pips2dbl) then '-- price moved below and is not random noice

    price_above=false
    trade_ok=true
    else

    if (Ask > entryprice + filter1* pips2dbl) then '-- price stayed above and is not random noice
    trade_ok=true
    end If
    end If
    else

    if (not price_above) then '-- price currently below

    if (Ask > entryprice + filter1* pips2dbl) then '-- price moved above and is not random noice

    price_above=true
    trade_ok=true
    else

    if (Bid < entryprice - filter1* pips2dbl) then '-- price stayed below and is not random noice
    trade_ok=true
    end If
    end If
    end If
    end If 'end of price above

    end If 'end of outer if

    '----- end of filter


    End Sub


    ''' <summary>
    ''' The function is generated when a new tick is received for any symbol
    ''' </summary>

    Public Sub OnTick(symbolName)
    'if PositionTotal() > 0 Then
    call EURUSD_Trader()
    'end if

    End Sub


    ''' <summary>
    ''' The function is generated when initialization script
    ''' </summary>

    Public Sub OnInit()
    ''''TODO: initialization method

    dim open,Digits,Symbol,piploc,Bid

    Symbol=ChartSymbol(0)
    Digits = 4
    SymbolInfoInteger cstr (Symbol), SYMBOL_PIP_LOCATION, piploc
    Point=10^piploc

    open=getOpen(0,Bars(0))
    Digits=AfterPoint(cstr(open))

    if(Digits=3 or Digits=5) Then
    pips2dbl = Point * 10
    pips2points = 10
    Digitspips = 1
    else
    pips2dbl = Point
    pips2points = 1
    Digitspips = 0
    end If
    dim HighAry(),LowAry(),OpenAry(),CloseAry(),tempAry()
    dim highVal,lowVal,closeVal,TypicalVal

    CopyHigh 0, 1, Bars (0), HighAry
    CopyLow 0, 1, Bars (0), LowAry
    CopyClose 0, 1, Bars (0), CloseAry

    SimpleMovingAverageOnArray HighAry,CInt (ma_value), tempAry
    highVal=tempAry(Bars(0))
    SimpleMovingAverageOnArray LowAry,CInt (ma_value), tempAry
    lowVal=tempAry(Bars(0))

    SimpleMovingAverageOnArray CloseAry,CInt (ma_value), tempAry
    closeVal=tempAry(Bars(0))

    TypicalVal = (highVal + lowVal + closeVal) / 3

    SymbolInfoDouble cstr(symbol),SYMBOL_BID,Bid
    if (Bid > TypicalVal) Then
    price_above=true
    else
    price_above=false
    end If
    End Sub

    Private Function AfterPoint(S )
    AfterPoint = Len(Split(S & ".", ".")(1))
    End Function


    ''' <summary>
    ''' The function is generated when deinitialization script
    ''' </summary>

    Public Sub OnDeInit()
    ''''TODO: deinitialization method

    End Sub


    ''' <summary>
    ''' The OnTimer function called when the timer event occurs
    ''' </summary>

    Public Sub OnTimer()
    ''''TODO: Timer Function
    End Sub

    ''' <summary>
    ''' The OnCalculate function called when a new candle received
    ''' </summary>

    Public Sub OnCalculate(symbol, symbolPeriod, openVal, highVal, lowVal, closeVal)

    End Sub
    ''' <summary>
    ''' Raise when all data are loaded after Login
    ''' </summary>

    Public Sub AllDataLoaded()

    End Sub
    ''' <summary>
    ''' Raise when Account Selected
    ''' </summary>

    Public Sub AccountSelected(accountNumber)

    End Sub
    ''' <summary>
    ''' Raise when the server returns order result
    ''' </summary>

    Public Sub OnOrderTrade(actionType ,orderID , returnValue)


    End Sub
    ''' <summary>
    ''' Raise when the server returns position result
    ''' </summary>

    Public Sub OnPositionTrade (actionType ,ticketID)
    dim OrderLots
    Symbol=ChartSymbol(0)
    SymbolInfoDouble cstr(symbol),SYMBOL_ASK,Ask
    SymbolInfoDouble cstr(symbol),SYMBOL_BID,Bid
    if(actionType=5) then
    PositionSelect(clng(ticketID))

    PositionGetDouble POSITION_AMOUNT,OrderLots
    if(getPositiontype()=TRADE_ACTION_SELL) then
    result = NewSLTPOrder(clng(ticketID),cdbl(OrderLots),cdbl(A sk+stoploss* pips2dbl),cdbl(Ask-takeprofit* pips2dbl))
    end If
    if(getPositiontype()=TRADE_ACTION_BUY) then
    result = NewSLTPOrder(clng(ticketID),cdbl(OrderLots),cdbl(B id-stoploss* pips2dbl),cdbl(Bid+takeprofit* pips2dbl))
    End If

    if(result = false) then
    PrintData "Error placing SL/TP order:" + errordescription(getLastError())
    exit sub
    end if
    end if
    End Sub
    ''' <summary>
    ''' Raise when the server returns Manage SL/TP Orders after calling RequestManageOrders method
    ''' </summary>

    public sub OnManageOrdersReceived(manageOrders)

    End Sub
    ''' <summary>
    ''' Generatd after requested prices from the server for new symbol
    ''' </summary>

    Public Sub PriceLoaded(TimeArr,OpenArr,HighArr,LowArr,CloseAr r)
    '''TODO: Implement the handler

    End Sub
    ''' <summary>
    ''' Generatd after change the chart period
    ''' </summary>

    Public Sub PeriodChanged (PeriodName, SymbolName)
    '''TODO: Implement the handler

    End Sub

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •