Position Indicator

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #154421 quote
    Crillezz
    Participant
    Veteran

    Hello! I need help building an indicator.

    I have an algo that can take three positions at different levels. The indicator should show how many positions it has taken.
    I am sending a picture of what the indicator should look like.
    Also sends a simple code we can start from.
    The idea is to be able to use this indicator for another algo that will hedge this position. I can make the indicator so that it shows the positions but not that it goes down to zero when algo closes the position

    // Definition of code parameters
    DEFPARAM CumulateOrders = True // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = RSI[14](close)
    c1 = (indicator1 < 12)
    
    IF not longonmarket and c1 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    IF longonmarket AND COUNTOFPOSITION=1 and close - tradeprice < -100*pointsize then
    Buy 1 CONTRACT AT MARKET
    endif
    
    IF longonmarket AND COUNTOFPOSITION=2 and close - tradeprice < 150*pointsize then Buy 1 CONTRACT AT MARKET endif //Take profit floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gains If LONGONMARKET and floatingprofit>20 then
    sell at market
    endif
    gdfgdfgddfg.png gdfgdfgddfg.png
    #154424 quote
    robertogozzi
    Moderator
    Master
    • Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.
    • Do not double post. Ask your question only once and only in one forum. All double posts will be deleted anyway so posting the same question multiple times will just be wasting your own time and will not get you an answer any quicker. Double posting just creates confusion in the forums
    Crillezz thanked this post
    #154426 quote
    Crillezz
    Participant
    Veteran

    Sorry. That was not the intention. I messed up.

    Now I see the insert code button 🙂

    #154433 quote
    Crillezz
    Participant
    Veteran
    // Definition of code parameters
    DEFPARAM CumulateOrders = True // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = RSI[14](close)
    c1 = (indicator1 < 30)
    
    
    IF not longonmarket and c1 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    IF longonmarket AND COUNTOFPOSITION=1 and close - tradeprice < -100*pointsize then
    Buy 1 CONTRACT AT MARKET
    endif
    
    IF longonmarket AND COUNTOFPOSITION=2 and close - tradeprice < 150*pointsize then
    Buy 1 CONTRACT AT MARKET
    endif
    set stop loss 130
    
    
    //Take profit
    floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gains
    
    If LONGONMARKET  and floatingprofit>20 then
    sell at market
    endif
    #154545 quote
    Vonasi
    Moderator
    Master

    Crillezz – Do not try to bump your own topic by quoting yourself. Can you imagine what a mess the forums would be if everyone did this?

    If you have not received a reply it is most likely because either other forum members don’t know the answer or other forum members don’t understand what you want.

    The forums are quieter at the weekends when markets are closed and people are away from their desks so some patience helps.

    I have deleted your post.

    #154598 quote
    Crillezz
    Participant
    Veteran

    What a mess. I have tried to delete it but I can´t.

    The more I try to arrange, the more wrong it becomes.

    The first code was incorrect. So I tried to change it. I don´t find the edit button.

    I’ve never had that problem before

    vxcvxcvxcvxc.png vxcvxcvxcvxc.png
    #154604 quote
    Vonasi
    Moderator
    Master

    You have five minutes to edit your posts – after that time has passed the edit button is no longer available and only moderators can edit or delete your posts for you. If it is the first post in a topic then only Nicolas can delete it and that action deletes the entire topic.

    Crillezz thanked this post
    #156108 quote
    Crillezz
    Participant
    Veteran

    Can someone help me with that indicator please.

    #156376 quote
    robertogozzi
    Moderator
    Master

    I assume that your line 17 should read -150.

    There you go:

    IF BarIndex = 0 THEN
       MyPositionCount = 0
       MyPositionPrice = 0
    ENDIF
    
    indicator1 = RSI[14](close)
    c1 = (indicator1 < 12)
     
    IF MyPositionCount = 0 AND c1 THEN
       MyPositionCount = 1
       MyPositionPrice = close
    ENDIF
     
    IF MyPositionCount = 1 and ((close - MyPositionPrice) < -100*pointsize) then
       MyPositionCount = MyPositionCount + 1
       MyPositionPrice = (MyPositionPrice + close) / 2
    endif
     
    IF MyPositionCount = 2 and ((close - MyPositionPrice) < -150*pointsize) then
       MyPositionCount = MyPositionCount + 1
       MyPositionPrice = ((MyPositionPrice * (MyPositionCount - 1)) + close) / MyPositionCount
    endif
    
    IF (MyPositionPrice - close) >= 130 THEN          //Stop Loss
       MyPositionCount = 0
       MyPositionPrice = 0
    ENDIF
    
    IF MyPositionCount THEN
       floatingprofit = (((close-MyPositionPrice)*pointvalue)*MyPositionCount)/pipsize
       If MyPositionCount > 0 and floatingprofit > 20 then
          MyPositionCount = 0
          MyPositionPrice = 0
       endif
    ENDIF
    
    RETURN MyPositionCount AS "MyPositionCount"
    Crillezz thanked this post
    #157942 quote
    Crillezz
    Participant
    Veteran

    Thanks Roberto. Just what I was looking for. But I have a problem. When I have to do the same thing but with a short position, it increases the position when it is profitable. It should only increase the position in case of loss. And it never reaches floating profit. I do not manage to change the code in the opposite direction

    #157943 quote
    Crillezz
    Participant
    Veteran
    IF BarIndex = 0 THEN
    MyPositionCount = 0
    MyPositionPrice = 0
    ENDIF
     
    indicator1 = RSI[14](close)
    c1 = (indicator1 < 12)
     
    IF MyPositionCount = 0 AND c1 THEN
    MyPositionCount = 1
    MyPositionPrice = close
    ENDIF
     
    IF MyPositionCount = 1 and ((close - MyPositionPrice) < -60*pointsize) then
    MyPositionCount = MyPositionCount + 1
    MyPositionPrice = (MyPositionPrice + close) / 2
    endif
     
    IF MyPositionCount = 2 and ((close - MyPositionPrice) < -90*pointsize) then
    MyPositionCount = MyPositionCount + 1
    MyPositionPrice = ((MyPositionPrice * (MyPositionCount - 1)) + close) / MyPositionCount
    endif
     
    
     
     
    
    
    
    //////////Short
    indicator1 = RSI[14](close)
    c2 = (indicator1 > 88)
    
    
    IF MyPositionCount = 0 AND c2 THEN
    MyPositionCount = -1
    MyPositionPrice1 = close
    ENDIF
    
    IF MyPositionCount = -1 and ((close + MyPositionPrice1) < -60*pointsize) then
    MyPositionCount = MyPositionCount - 1
    MyPositionPrice1 = (MyPositionPrice1 + close) / 2
    endif
    
    IF MyPositionCount = -2 and ((close + MyPositionPrice1) < -90*pointsize) then
    MyPositionCount = MyPositionCount - 1
    MyPositionPrice1 = ((MyPositionPrice1 * (MyPositionCount - 1)) + close) / MyPositionCount
    endif
    
    
    IF (MyPositionPrice1 - close) >= 130 THEN          //Stop Loss
    MyPositionCount = 0
    MyPositionPrice1 = 0
    ENDIF
    
    
    IF MyPositionCount THEN
    floatingprofit = (((close-MyPositionPrice)*pointvalue)*MyPositionCount)/pipsize
    If MyPositionCount > 0 and floatingprofit > 20 then
    MyPositionCount = 0
    MyPositionPrice = 0
    endif
    If MyPositionCount < 0 and floatingprofit > 20 then
    MyPositionCount = 0
    MyPositionPrice = 0
    endif
    ENDIF
    
    
    RETURN MyPositionCount AS "MyPositionCount"
    #157952 quote
    robertogozzi
    Moderator
    Master

    Lines 40 and 45 should read:

    MyPositionPrice1 - close

    Just after line 58 (before line 59), insert:

    floatingprofit1 = (((MyPositionPrice1-close)*pointvalue)*abs(MyPositionCount))/pipsize

    and at line 63 you should reference floatingprofit1.

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

Position Indicator


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Crillezz @crillezz Participant
Summary

This topic contains 11 replies,
has 3 voices, and was last updated by robertogozzi
5 years, 1 month ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/19/2020
Status: Active
Attachments: 2 files
Logo Logo
Loading...