brent crude eur1 mini 5min code

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #11959 quote
    Kenneth KvistadKenneth Kvistad
    Participant
    Senior
    Hi.. I am new too this and are not so good to wrigh own codes. I would like to share my strategy I am currently running live and hope someone can help me with a code to make it buy extra contract if I loose 2 in a row ect. I tried to apply a martin gale code by my self but with no sucsess.
    Brent-crude-5-min-ferdig-moddet.itf brent-crude-live-acc.png brent-crude-live-acc.png
    #11979 quote
    ElsborgtradingElsborgtrading
    Participant
    Veteran
    There were some code somewhere here that buys more contract when winning, i’m sure that could be changed to what you want. Here is the basic. I’m not finished with it yet as it has some non linear risks that needs to be adressed. Btw it was orginally Grizzlys code.
    MaxPositionA=100
    Account=5000
    Ratio=1 
    Equity = (Strategyprofit+account)
    
    Risk = min(round(Ratio*Equity/100000)*1,MaxPositionA)
    
    Losses = positionperf(1)<0 and positionperf(2)<0 and positionperf(3)<0
    streak = positionperf(1)>0 and positionperf(2)>0 and positionperf(3)>0
    
    if losses then
    PositionSize  = max(abs(round(max(3+risk-2,risk-2))),2)
    elsif not losses then
    PositionSize  = max(abs(round(max(3+risk,risk))),2)
    Endif
    if streak then
    PositionSize  = max(abs(round(max(5+risk,risk))),2)
    
    Endif
    grizzly thanked this post
    #11985 quote
    Kenneth KvistadKenneth Kvistad
    Participant
    Senior
    posistin size is not working. How do I change it so its for buy/sell contracts?
    #11988 quote
    Kenneth KvistadKenneth Kvistad
    Participant
    Senior
    can someone help me with filling it in for me in my code? or a martin gale code? DEFPARAM CumulateOrders = False // Cumulating positions deactivated //defparam flatbefore = 230000 //defparam flatafter = 065500 // Conditions to enter long positions indicator1 = TimeSeriesAverage[29](close) indicator2 = WilderAverage[66](close) c1 = (indicator1 >= indicator2) indicator3 = SMI[9,6,14](close) c2 = (indicator3 CROSSES OVER -44) IF c1 AND c2 THEN BUY 2 CONTRACT AT MARKET ENDIF // Conditions to enter short positions indicator4 = TimeSeriesAverage[10](close) indicator5 = WilderAverage[86](close) c3 = (indicator4 <= indicator5) indicator6 = SMI[6,1,16](close) c4 = (indicator6 >= 45) IF c3 AND c4 THEN SELLSHORT 2 CONTRACT AT MARKET ENDIF //************************************************************************ //trailing stop function trailingstart = 34 //trailing will start @trailinstart points profit trailingstep = 1 //trailing step to move the “stoploss” //reset the stoploss value IF NOT ONMARKET THEN newSL=0 ENDIF //manage long positions IF LONGONMARKET THEN //first move (breakeven) IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN newSL = tradeprice(1)+trailingstep*pipsize ENDIF //next moves IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN newSL = newSL+trailingstep*pipsize ENDIF ENDIF //manage short positions IF SHORTONMARKET THEN //first move (breakeven) IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN newSL = tradeprice(1)-trailingstep*pipsize ENDIF //next moves IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN newSL = newSL-trailingstep*pipsize ENDIF ENDIF //stop order to exit the positions IF newSL>0 THEN SELL AT newSL STOP EXITSHORT AT newSL STOP ENDIF //************************************************************************ SET STOP ploss 78//78 SET TARGET pPROFIT 136//98
    #11989 quote
    ElsborgtradingElsborgtrading
    Participant
    Veteran
    change: IF c1 AND c2 THEN BUY 2 CONTRACT AT MARKET ENDIF to IF c1 AND c2 THEN BUY PositionSize CONTRACT AT MARKET ENDIF and change IF c3 AND c4 THEN SELLSHORT 2 CONTRACT AT MARKET ENDIF to IF c3 AND c4 THEN SELLSHORT PositionSize CONTRACT AT MARKET ENDIF
    #12009 quote
    Kenneth KvistadKenneth Kvistad
    Participant
    Senior
    OK   thanks alot for the help
    #12010 quote
    NicolasNicolas
    Keymaster
    Legend
    #12011 quote
    Kenneth KvistadKenneth Kvistad
    Participant
    Senior
    Thanks alot
    #12040 quote
    Kenneth KvistadKenneth Kvistad
    Participant
    Senior
    Can you please explain me how your Money management strategy works Elsborgtrading? like risk= ? and how account works? if it looses 3 in a row it will buy 5 contracts right ? and if I change the
    Risk = min(round(Ratio*Equity/100000)*1,MaxPositionA) from 100000 to lets say 100 I get a insane profit that I dont really understand since when I check the 
    orderlist it goes from lets say 5 and 10 contracts and then suddenly to 1000 contracts if I change
    MaxPositionA=100 to 1000.
    
    As I understand I tought it would go from lest say 5 contracts to 10 to 20 ect. depending on your account size. but with me it jumps really fast.
    
    
    
    Better understanding if I just put my code up here: //————————————————————————- // Main code : MySystem(95) //————————————————————————- //————————————————————————- // Main code : MySystem(65) //————————————————————————- //————————————————————————- // Main code : MySystem(62) //————————————————————————- DEFPARAM CumulateOrders = False // Cumulating positions deactivated //defparam flatbefore = 230000 //defparam flatafter = 065500 //MGT MaxPositionA=1000 Account=1000 Ratio=1 Equity = (Strategyprofit+account) Risk = min(round(Ratio*Equity/100)*1,MaxPositionA) Losses = positionperf(1)<0 and positionperf(2)<0 and positionperf(3)<0 streak = positionperf(1)>0 and positionperf(2)>0 and positionperf(3)<0 if losses then PositionSize = max(abs(round(max(2+risk-2,risk-2))),2) elsif not losses then PositionSize = max(abs(round(max(2+risk,risk))),2) Endif if streak then PositionSize = max(abs(round(max(5+risk,risk))),2) Endif // Conditions to enter long positions indicator1 = TimeSeriesAverage[29](close) indicator2 = WilderAverage[66](close) c1 = (indicator1 >= indicator2) indicator3 = SMI[9,6,14](close) c2 = (indicator3 CROSSES OVER -44) IF c1 AND c2 THEN BUY PositionSize CONTRACT AT MARKET ENDIF // Conditions to enter short positions indicator4 = TimeSeriesAverage[10](close) indicator5 = WilderAverage[86](close) c3 = (indicator4 <= indicator5) indicator6 = SMI[6,1,16](close) c4 = (indicator6 >= 45) IF c3 AND c4 THEN SELLSHORT PositionSize CONTRACT AT MARKET ENDIF //************************************************************************ //trailing stop function trailingstart = 34 //trailing will start @trailinstart points profit trailingstep = 1 //trailing step to move the “stoploss” //reset the stoploss value IF NOT ONMARKET THEN newSL=0 ENDIF //manage long positions IF LONGONMARKET THEN //first move (breakeven) IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN newSL = tradeprice(1)+trailingstep*pipsize ENDIF //next moves IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN newSL = newSL+trailingstep*pipsize ENDIF ENDIF //manage short positions IF SHORTONMARKET THEN //first move (breakeven) IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN newSL = tradeprice(1)-trailingstep*pipsize ENDIF //next moves IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN newSL = newSL-trailingstep*pipsize ENDIF ENDIF //stop order to exit the positions IF newSL>0 THEN SELL AT newSL STOP EXITSHORT AT newSL STOP ENDIF //************************************************************************ SET STOP ploss 78//78 SET TARGET pPROFIT 136//98
    #12138 quote
    ElsborgtradingElsborgtrading
    Participant
    Veteran
    You should not change those numbers. If any only the ratio in steps of 5 for every 15000 gain. You will at some point blow your account because you will be gambling with almost everything every time. a small negative P/L will result in a margin call and your positions will be automatic closed. I don’t understand fully the money management code as it’s not linear (equity vs risk), but yes when you win 3 times it will adjust for more contracts. Problem is if you run this code with only 1000 euro to start with (account=1000) you will be almost gambling with 7,8% every time you trade ONE contract with a SL at 78. two position will double your gambling risk. so if you change the risk factor from 100000 to 100 and maxposition to 1000, you will get insane profit, but only in the backtest. 2 lost trades IRL you will blow your account. Risk = min(round(Ratio*Equity/100000)*1,MaxPositionA) in fact I would consider lower the risk like this, however it’s up to you what you want to gamble with, so you can play with the numbers as you see the difference.
    MaxPositionA=100
    Account=5000
    Ratio=1
    Equity = (Strategyprofit+account)
    
    Risk = min(round(Ratio*Equity/100000)*1,MaxPositionA)
    
    Losses = positionperf(1)<0 and positionperf(2)<0 and positionperf(3)<0
    streak = positionperf(1)>0 and positionperf(2)>0 and positionperf(3)>0
    
    if losses then
    PositionSize  =max(ABS(round(max(1+Risk-2,Risk-2))),1)
    elsif not losses then
    PositionSize  =max(ABS(round(max(2+Risk,Risk))),2)
    endif
    if streak then
    PositionSize  = max(abs(round(max(3+risk,risk))),2)
    Endif
    grizzly thanked this post
    #12139 quote
    Kenneth KvistadKenneth Kvistad
    Participant
    Senior
    If i whant the code to.buy after two losses do i just take away the last postionperf on each line on.loss and streak and the last risk on each line on positionsize? google have a max loss in a row of two.according my.backtest last 9 months
    #12146 quote
    ElsborgtradingElsborgtrading
    Participant
    Veteran
    I’m not sure I understand you- you alway buy 😛 but from you orginal post you want to buy extra contract if loose 2 times? But still you are “curve Fitting” you don’t know if this will be the case in the future. I’s better to play it safe. anyway I think it will be this
    MaxPositionA=100
    Account=5000
    Ratio=1
    Equity = (Strategyprofit+account)
    
    Risk = min(round(Ratio*Equity/100000)*1,MaxPositionA)
    
    Losses = positionperf(1)<0 and positionperf(2)<0
    streak = positionperf(1)>0 and positionperf(2)>0 and positionperf(3)>0
    
    if losses then
    PositionSize  =max(abs(round(max(5+risk,risk))),2)
    elsif not losses then
    PositionSize  =max(ABS(round(max(2+Risk,Risk))),2)
    endif
    if streak then
    PositionSize  = max(abs(round(max(3+risk,risk))),2)
    Endif
    Nicolas also made another MM code, that keeps betting more when you win. you can try it out
    Capital = 10000 
    Risk = 0.01 
    StopLoss = 10 // Could be our variable XREM Calculate contracts
    equity = Capital + StrategyProfit
    maxrisk = round(equity*Risk)
    PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
    
    #12149 quote
    Kenneth KvistadKenneth Kvistad
    Participant
    Senior
    Thanks alot.   You just did what i tought I had too do. But still wonder is streak the same in.the code you wrote that if win 3 in a row you buy 3 contracts. If looses 2 in a row i buy 5 contracts and  

    Elsif not looses it will buy standard 2 contracts?

    Sorry for all the questions.

     

    It have been to great help

    #12152 quote
    ElsborgtradingElsborgtrading
    Participant
    Veteran
    Hi Kenneth 🙂 well the intended and initial code was to add more contracts if you win 3 times in a row. actually for 5 contracts. if you loose 3 times in a row it will down scale to 1 contract and or else use 3 contracts. But I think that was a bit risky if you only had a 1000 Euro account to begin with, so I change it a bit. But really you can change the code for what ever fits your riskprofile. then you wanted to add more if you loose 2 times, so I change the “losses” variable to only have 2 periods. it is easy spotted if you compare the “streak” variable. Then I took the equation from the ” if streak then” test and added a 5, so you would have more contracts if you loose 2 times in a row( this equation was the original from the “if streak then” test) The contracts would be increased along with your gain which is your “Equity” variable. How ever I found out that this process was not linear. I will add a excel spreadsheet that will show you the  curve for risk vs equity. and you can also play with the numbers and see how many contracts vs. equity you will get. It will also give you an idea of how much you are risking- and to be honest It is really a lot you would risk unless you start out with a 30000 euro account. So in this process of finding out the risk management code, I must say that if I was to trade with live money I would start out with 1 fixed contract to see where it would take me, and then I would consider using the code Nicholas made, because here you have to earn you right to add more contract, where this is not the case here. Cheers Kasper
    Nicolas thanked this post
    money-manegement.xlsx
Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

brent crude eur1 mini 5min code


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 13 replies,
has 3 voices, and was last updated by ElsborgtradingElsborgtrading
10 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/20/2016
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...