entry price long above close of pinbar

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #219326 quote
    jellevisser
    Participant
    New

    Hello,

    I would like some help with the following. I created an indicator which is looking at VSA and pinbar if the conditions are met indicator = -1. (long signal)

    Now I would like to that when indicator is -1 at the next candle it buys 1 contract at entry (entry = close + 10 pips) below is the code, it is not working because it is not opening a position at all, i tried different things but i dont get it working.

    How should i write the code in order that it works? many thanks in advance

     

    // Definitie van code parameters
    DEFPARAM CumulateOrders = False // Opstapelen posities gedeactiveerd

    // Condities om long posities te openen
    indicator1 = CALL “VSA_final pinbar”
    c1 = (indicator1 = -1)
    entry = close[1] + (10*pipsize)

    IF c1 and tradeprice > entry THEN
    BUY 1 CONTRACT AT market
    ENDIF

    // Stops en targets
    SET STOP pLOSS 25
    SET TARGET pPROFIT 50

    #219328 quote
    JS
    Participant
    Senior

    Hi Jelle,

    I set the indicator “VSA_final pinbar” for the test to -1…

    After that, you need to enter the “entry” under an “If… then” statement otherwise it changes constantly when processing a new “Close”…

    You cannot use “tradeprice > entry” here because the “tradeprice” only exists after opening a “trade”… instead of “tradeprice”, use the “Close”…

     
    // Definitie van code parameters
    DEFPARAM CumulateOrders = False // Opstapelen posities gedeactiveerd
    
    // Condities om long posities te openen
    //indicator1 = CALL "VSA_final pinbar"
    
    c1=indicator1 //c1 = Call "VSA_final pinbar"
    indicator1=-1 //Only for testing
    
    If c1 = -1 then
    entry = close[1] + (10*pipsize)
    EndIf
    
    IF c1 and Close > entry THEN
    BUY 1 CONTRACT AT market
    ENDIF
    
    // Stops en targets
    SET STOP pLOSS 25
    SET TARGET pPROFIT 50
    #219329 quote
    jellevisser
    Participant
    New
    Hello JS thanks for your reply, i tested your proposal but i can see that it still buys at market after the pinbar is formed and not 10 pips higher than close. I attached a screenshot for clarification, any other suggestions? I tried to add an attachment but is apparently not working, I hope it is clear what i mean.
    #219330 quote
    JS
    Participant
    Senior

    Hi Jelle,

    The system buys “at Market” because your code says “Buy 1 contract at Market”… 🙂

    If you want to buy at the previous close + 10*pipsize then you have to use a STOP order…  

    // Definitie van code parameters
    DEFPARAM CumulateOrders = False // Opstapelen posities gedeactiveerd
    
    // Condities om long posities te openen
    //indicator1 = CALL "VSA_final pinbar"
    
    c1=indicator1 //c1 = Call "VSA_final pinbar"
    indicator1=-1 //Only for testing
    
    If c1 = -1 then
    entry = close + (10*pipsize)
    EndIf
    
    IF c1 and NOT OnMarket THEN
    BUY 1 CONTRACT AT entry STOP
    ENDIF
    
    // Stops en targets
    SET STOP pLOSS 25
    SET TARGET pPROFIT 50

    #219357 quote
    PeterSt
    Participant
    Master
    Jelle, according to what you designed yourself, this is what resembles that :
    // Definitie van code parameters
    DEFPARAM CumulateOrders = False // Opstapelen posities gedeactiveerd
    
    // Condities om long posities te openen
    indicator1 = CALL “VSA_final pinbar”
    c1 = (indicator1 = -1)
    entry = close[1] + (10*pipsize)
    
    IF c1 and close > entry THEN   // No TradePrice but Close.
      BUY 1 CONTRACT AT market
    ENDIF
    
    // Stops en targets
    SET STOP pLOSS 25
    SET TARGET pPROFIT 50
    
    Graph Indicator1   // Check for whether the Indicator outcome does what you intend.
    If it now does not work, it will be because of wrong logic – not because of technicalities.
    #219574 quote
    jellevisser
    Participant
    New
    Hi Peter, I think my logic is not correct, but how do i write the code different so that it opens a position 10 pips below the close (for short) of the pinbar?
    #219605 quote
    PeterSt
    Participant
    Master
    Hi again Jelle,
    // Definitie van code parameters
    DEFPARAM CumulateOrders = False // Opstapelen posities gedeactiveerd
     
    // Condities om long posities te openen
    indicator1 = CALL “VSA_final pinbar”
    c1 = (indicator1 = 1)   // Is this correct for Short ?
    entry = close[0] - (10*pipsize)   // Changed [1] to [0] and + to -.
     
    IF c1 and close < entry THEN   // It is not said that you want it like this.
      SellShort 1 CONTRACT AT market
    ENDIF
     
    // Stops en targets
    SET STOP pLOSS 25
    SET TARGET pPROFIT 50
     
    Graph Indicator1   // Check for whether the Indicator outcome does what you intend.
    “It is not said that you want it like this”. Why ? You first seem to wait until the price is extra-low, and then go Short (SellShort). This seems counter-productive, though obviously it can be part of your strategy. My senses tell me this : You have that Indicator (with for us unknown content) and it tells to go Short. What I would do is wait for the better price, which would be a higher price than the price at the moment of the Indicator telling you to go Short. Notice that you are always one bar behind. Thus for example, when the Indicator tells you that you can go Short, and the TimeFrame is 1 minute (the chart is set to bars of 1 minute) then 1 minute late you will “see” this (the program code is called at the end of each bar hence minute). What’s crucial for the consistency are this considerations :
    1. When the Indicator tells to go Short, the price could be dropping more and my “senses” above are wrong and won’t apply (no price will be higher than when the indicator “detected” and you will wait forever for an entry.
    2. When the Indicator tells to go Short, it may be better not to look for an even lower price, because within that past minute it may never have happened.
    Taking both into consideration, this would work best :
    IF c1 THEN   // So just depend on the Indicator.
      SellShort 1 CONTRACT AT market 
    ENDIF
    But always watch the outcome of Indicator1 (with graph) because if that is not doing what you expect (it may remain 0 always) then no entry will be there ever. Also, maybe ensure yourself that the Indicator returns -1 indeed for Long (and I suppose 1 for Short then) because it does not seem logical to me (-1 for Short would be logical to me). Have fun ! Peter
    #219759 quote
    jellevisser
    Participant
    New
    Hi Peter, this is the code I use, when green pinbar in combination with VSA it give signal -1 for long and red pinbar with VSA 1 for short. so if a green pinbar is formed it gives a signal of 1 and next candle the program buys a long, this strategy works reasonable but i see too often that when a green pinbar is formed the price drops further. I would like to have a condition that if a green pinbar is formed and the close of the pinbar is lets say 100 that the program on the next candel buys one long contract at 110. in the example when a green pinbar is formed and the close is 100 and the next candel drops below 100 the program should not buy and wait for the next opportunity.
    //met pinbar alleen long als pinbar groen is en short als deze rood is
    c1= open - close
    c2= open[1]-close[1]
    
    if c1 < 0 then
    c1 =(open - close)*-1
    else
    c1 =(open - close)
    endif
    if c2 < 0 then
    c2 =(open[1]-close[1])*-1
    else
    c2 =(open[1]-close[1])
    endif
    
    if (c1<c2) then
    VSAkoers =1
    else
    vsakoers = 0
    endif
    
    //correctie voor volume
    indicator1 = Volume
    c3 = (indicator1 > indicator1[1])
    
    if indicator1 > indicator1[1] then
    VSAvolume = 1
    else
    VSAvolume = 0
    endif
    
    //correctie voor low van de x periods indicator voor long signaal
    c4 = lowest [5](low)
    if low <c4 [1] then
    VSAlow = -1
    else
    VSAlow = 0
    endif
    
    //correctie voor high van de x periods indicator voor short signaal
    c5 = highest [5](high)
    if high > c5 [1] then
    VSAhigh = 1
    else
    VSAhigh = 0
    endif
    
    //groene pinbar voor long / rode pinbar voor short
    pinbarcolor = 0
    
    if open < close then
    pinbarcolor = 1 //short signaal
    else
    pinbarcolor = -1 // long signaal
    endif
    
    
    //correctie voor pinbar
    shootingstar = 0
    hammer = 0
     
    IF (high - low) > 2* abs(close - open) THEN
    IF (open - low) < 0.4*(high - low) OR (close - low) < 0.4*(high-low) THEN
    shootingstar = -1
    ENDIF
    IF (high - open) < 0.4*(high - low) OR (high - close) < 0.4*(high-low) THEN
    hammer = 1
    ENDIF
    endif
    
    c8 = close[1]- close [5] //distance from candle 5 to 1 for short
    if c8 > 10 then
    c8 = 1
    else
    c8=0
    endif
    
    c9= close[5]- close [1]//distance from candle 5 to 1 for long
    if c9 > 10 then
    c9 = 1
    else
    c9=0
    endif
    
    //final voorwaarden
    if VSAkoers =1 and VSAvolume = 1 and VSAhigh=1 and shootingstar = -1 and pinbarcolor = -1  then
    VSA=1 //short signaal
    else
    if VSAkoers =1 and VSAvolume = 1 and VSAlow=-1 and hammer = 1 and pinbarcolor = 1  then
    VSA=-1// longsignaal
    else
    VSA=0
    endif
    endif
    return VSA as "VSA"
    
    #219798 quote
    PeterSt
    Participant
    Master
    Hi Jelle, It would be nice if you coded that indicator yourself – then we could try to let it work. I (also) mean : I like to have it working myself. Why ? see the first picture below. The purple down-arrow in the left hand side is yours. The yellow down-arrow in the right is mine. Notice that the pinbar I use is the bar prior to the bar prior to the entry. Thus, green in order to go short. Yours is red in order to go short, and I don’t think that is right. However, I personally go mad of upside-down thinking (what this requires) in general. Thus, the “I don’t think that is right” is actually not wrong, BUT see the 4th picture and try to wrap your head around why it is different. And why mine (yellow) looks better for start-off (keep in mind I use two bars to get to the decision). Notice that I did not apply further code after calling the indicator.  You, in your original post did, but I don’t think that is entry related – only best entry. I do similar in my general code and it is applied to your entry just as well. EXPLANATION I coincidentally apply the same “pinbar” method but by very different (incomparable) means. The backtest result of my method you see in the 2nd picture. Your backtest result shows in the 3rd picture. Notice that the code for both your and my method is completely the same – only the pinbar method was replaced hence only the entry-means was replaced. Your method is heavily Short oriented, which can’t be reality (this is EUR/USD and nothing in my book tells that it should be short-oriented, even if the EUR is falling gradually lately. This is not how the pinbar method would operate, on the 1 minute TimeFrame I use. So something has to be wrong in the basis. If you have made this code yourself, I would be nice if you put as much comment in there as you can bear. This should lead to finding the culprit(s). Anyway I can’t read it as how it is, because I did not dive into how this method should really be approached (and I don’t give myself the time to find out 😉 ). In any event the entries are there, so nothing wrong with that in itself. Regards, Peter
    image_2023-08-26_095126848.png image_2023-08-26_095126848.png image_2023-08-26_095927172.png image_2023-08-26_095927172.png image_2023-08-26_095946625.png image_2023-08-26_095946625.png image_2023-08-26_101942790.png image_2023-08-26_101942790.png
    #219816 quote
    jellevisser
    Participant
    New
    Hi Peter, I wrote the code myself, it has to be optimized. I am struggling with the settings for stoploss and profit. I use it now as an entry, as soon the program buys i stop the program and manage the trade my self because i can have a much better exit. But you have a nice program that makes a profit! impressive result if I look at the your first picture it looks like it is buying a certain amount of pips above the previous close I cant see by how much, but if I backt test mine it always buys at market. why should the EUR/USD not be shorted? just for my interest I am still learning about trading.
    #219819 quote
    PeterSt
    Participant
    Master
    About the Buy at Market : see JS’s response. Thus the answer is simple : because you give the command to buy At Market (price). Buy at xx Limit (JS uses Stop) would wait for the price to go there and if touched, it buys. And Yes, I use at xx Limit there too. Of course EUR/USD can be shorted, but your Indicator makes it Short-Heavy. With that I mean that there’s way more Shorts than Longs, and that is not right. It should balance-out (about-ish). And since it does not, something has to be wrong (x – close vs close – x or something). Btw, if you swap the signals (to 1 for Long and -1 for Short) it performs better – usually no a good sign ;-). As said, if you put comments to everything, I can try to let it work, also based upon (PRT) experience. Comments like “0.4 means at least 40% of the candle must be the wick size” (just making up something). It is not an easy indicator to work with because you can have many false indications, like what the descriptions will tell you “don’t use it in the middle of a consolidation” (these are often spikey to begin with and go nowhere until …). So it is key to know that, and soon you will run into endless trials to cover for that. What you saw from my example screenshot covers for that as far as I got it at this moment, but … your Pinbar indicator made use of that very same environment (as said, it is within the same code, only the Entry “Pinbar” method was replaced by yours). Small hint : entry means like these will lead to many losing trades (like more than 50%) but this is fine as long as the P/L Ratio is OK (net you win more money than you lose). IOW don’t be disappointed if your Winning Trades % remains low. Later (if the net result is consistently positive) you just throw more money at it.
    In case you don’t know it yet : Replace your SET STOP pLOSS 25 with SET STOP pLOSS pLossVar and put pLossVar in an iterating Optimization Variable (see the wrench in the top-left of the Editor screen). Let it vary from 1 to 100 and observe the results. Same with the profit target. Same with everything … And have fun …
    coincatcha thanked this post
    #219831 quote
    jellevisser
    Participant
    New
    Hi peter, thanks for you support and help. I will continue in the end it will work, I hope.
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

entry price long above close of pinbar


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 11 replies,
has 3 voices, and was last updated by jellevisser
2 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/19/2023
Status: Active
Attachments: 4 files
Logo Logo
Loading...