NexusFi: Find Your Edge


Home Menu

 





MAMA with Buy Sell Signals and P&L


Discussion in ThinkOrSwim

Updated
    1. trending_up 9,626 views
    2. thumb_up 2 thanks given
    3. group 1 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread

MAMA with Buy Sell Signals and P&L

  #1 (permalink)
ebtrader
east brunswick
 
Posts: 3 since Dec 2010
Thanks Given: 0
Thanks Received: 3

I put some Buy/Sell Signals in Ehler's MAMA and I wanted to integrate VicEquity's P&L to keep a running total of P&L from this strategy - any ideas on how to integrate them? I have pasted the code for both below:

#################################
# Study: VicEquity

# Date: Dec 1 2010
# Purpose: to display current P/L equity position on chart window.
#################################

# User Inputs:
input TransactionType = {default Long, "Short"}; # Define if we are going long or short
input StartPrice = 1190; # price at which we initated the position
input ContractSize = 1; # number of contracts bought or sold
input Equity = {default "/ES", "/6A", "/TF", "/YM", "/NQ", "/6E", "/GC", "/CL"}; # drop down list of several symbols

def CurPrice = close; # we'll measure against the current close price (could be variable pointing to High or Low or H+L/2 etc...)

# different futures have different multipliers... let's hard code it for one time...great if it can be pulled from some library/repository
def FuturesMultiplier;
def tickSize;

switch (Equity) {
case "/ES": # S & P E-mini
FuturesMultiplier = 12.5;
tickSize = .25;

case "/6A": # Aussie
FuturesMultiplier = 125000;
tickSize = 1; # I have no idea, someone else can look this up
default:
FuturesMultiplier = 1;
tickSize = 1;
}

def ProfitLoss;
switch (TransactionType) {
case "Long":
ProfitLoss = (CurPrice - StartPrice)/tickSize * ContractSize * FuturesMultiplier;
case "Short":
ProfitLoss = (StartPrice - CurPrice)/tickSize * ContractSize * FuturesMultiplier;

}

# Label on top left corner
# paste a label on upper chart showing the P/L for the contract..
AddChartLabel(yes,
concat(getSymbolPart(), concat(TransactionType, concat(" : $", ProfitLoss))),
if ProfitLoss >= 0 then color.green else color.red );


# Here is Ehler's MAMA:
# hint: <b>Ehler's Mesa Adaptive Moving Average</b> using Ray's clean version
# of the homodyne discriminator.
#

# MIT License
# Copyright (c) <2010> <Radford Juang>
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
#

script WMA_Smooth {
input price = hl2;
plot smooth = (4 * price
+ 3 * price[1]
+ 2 * price[2]
+ price[3]) / 10;
}

script Phase_Accumulation {
# This is Ehler's Phase Accumulation code. It has a full cycle delay.
# However, it computes the correction factor to a very high degree.
#
input price = hl2;

rec Smooth;
rec Detrender;
rec Period;
rec Q1;
rec I1;
rec I1p;
rec Q1p;
rec Phase1;
rec Phase;
rec DeltaPhase;
rec DeltaPhase1;
rec InstPeriod1;
rec InstPeriod;
def CorrectionFactor;

if barNumber() <= 5
then {
Period = 0;
Smooth = 0;
Detrender = 0;
CorrectionFactor = 0;
Q1 = 0;
I1 = 0;
Q1p = 0;
I1p = 0;
Phase = 0;
Phase1 = 0;
DeltaPhase1 = 0;
DeltaPhase = 0;
InstPeriod = 0;
InstPeriod1 = 0;
} else {
CorrectionFactor = 0.075 * Period[1] + 0.54;

# Smooth and detrend my smoothed signal:
Smooth = WMA_Smooth(Price);
Detrender = ( 0.0962 * Smooth
+ 0.5769 * Smooth[2]
- 0.5769 * Smooth[4]
- 0.0962 * Smooth[6] ) * CorrectionFactor;

# Compute Quadrature and Phase of Detrended signal:
Q1p = ( 0.0962 * Detrender
+ 0.5769 * Detrender[2]
- 0.5769 * Detrender[4]
- 0.0962 * Detrender[6] ) * CorrectionFactor;
I1p = Detrender[3];

# Smooth out Quadrature and Phase:
I1 = 0.15 * I1p + 0.85 * I1p[1];
Q1 = 0.15 * Q1p + 0.85 * Q1p[1];

# Determine Phase
if I1 != 0 then {
# Normally, ATAN gives results from -pi/2 to pi/2.
# We need to map this to circular coordinates 0 to 2pi

if Q1 >= 0 and I1 > 0 then { # Quarant 1
Phase1 = ATan(absValue(Q1/I1));
} else if Q1 >= 0 and I1 < 0 then { # Quadrant 2
Phase1 = Double.PI - ATan(absValue(Q1/I1));
} else if Q1 < 0 and I1 < 0 then { # Quadrant 3
Phase1 = Double.PI + ATan(absValue(Q1/I1));
} else { # Quadrant 4
Phase1 = 2*Double.PI - ATan(absValue(Q1/I1));
}
} else if Q1 > 0 then { # I1 == 0, Q1 is positive
Phase1 = Double.PI/2;
} else if Q1 < 0 then { # I1 == 0, Q1 is negative
Phase1 = 3*Double.PI/2;
} else { # I1 and Q1 == 0
Phase1 = 0;
}

# Convert phase to degrees
Phase = Phase1 * 180 / Double.PI;

if Phase[1] < 90 and Phase > 270 then {
# This occurs when there is a big jump from 360-0
DeltaPhase1 = 360 + Phase[1] - Phase;
} else {
DeltaPhase1 = Phase[1] - Phase;
}

# Limit our delta phases between 7 and 60
if DeltaPhase1 < 7
then {
DeltaPhase = 7;
} else if DeltaPhase1 > 60 then {
DeltaPhase = 60;
} else {
DeltaPhase = DeltaPhase1;
}

# Determine Instantaneous period:
InstPeriod1 =
-1*(fold i=0 to 40 with v=0 do
if v < 0 then
v
else if v > 360 then
-i
else
v + getValue(DeltaPhase, i, 41)
);

if InstPeriod1 <= 0 then {
InstPeriod = InstPeriod[1];
} else {
InstPeriod = InstPeriod1;
}

Period = 0.25*InstPeriod + 0.75*Period[1];
}
plot DC = period;
}

script Ehler_MAMA {
input price = hl2;
input FastLimit = 0.5;
input SlowLimit = 0.05;


rec Period;
rec Period_raw;
rec Period_cap;
rec Period_lim;

rec Smooth;
rec Detrender;
rec I1;
rec Q1;
rec jI;
rec jQ;
rec I2;
rec Q2;
rec I2_raw;
rec Q2_raw;

rec Phase;
rec DeltaPhase;
rec DeltaPhase_raw;
rec alpha;
rec alpha_raw;

rec Re;
rec Im;
rec Re_raw;
rec Im_raw;

rec SmoothPeriod;
rec vmama;
rec vfama;

def CorrectionFactor = Phase_Accumulation(price).CorrectionFactor;

if barNumber() <= 5
then {
Smooth = 0;
Detrender = 0;

Period = 0;
Period_raw = 0;
Period_cap = 0;
Period_lim = 0;
I1 = 0;
Q1 = 0;
I2 = 0;
Q2 = 0;
jI = 0;
jQ = 0;
I2_raw = 0;
Q2_raw = 0;
Re = 0;
Im = 0;
Re_raw = 0;
Im_raw = 0;
SmoothPeriod = 0;
Phase = 0;
DeltaPhase = 0;
DeltaPhase_raw = 0;
alpha = 0;
alpha_raw = 0;
vmama = 0;
vfama = 0;
} else {
# Smooth and detrend my smoothed signal:
Smooth = WMA_Smooth(Price);
Detrender = ( 0.0962 * Smooth
+ 0.5769 * Smooth[2]
- 0.5769 * Smooth[4]
- 0.0962 * Smooth[6] ) * CorrectionFactor;

Q1 = ( 0.0962 * Detrender
+ 0.5769 * Detrender[2]
- 0.5769 * Detrender[4]
- 0.0962 * Detrender[6] ) * CorrectionFactor;
I1 = Detrender[3];

jI = ( 0.0962 * I1
+ 0.5769 * I1[2]
- 0.5769 * I1[4]
- 0.0962 * I1[6] ) * CorrectionFactor;

jQ = ( 0.0962 * Q1
+ 0.5769 * Q1[2]
- 0.5769 * Q1[4]
- 0.0962 * Q1[6] ) * CorrectionFactor;

# This is the complex conjugate
I2_raw = I1 - jQ;
Q2_raw = Q1 + jI;

I2 = 0.2*I2_raw + 0.8*I2_raw[1];
Q2 = 0.2*Q2_raw + 0.8*Q2_raw[1];

Re_raw = I2*I2[1] + Q2*Q2[1];
Im_raw = I2*Q2[1] - Q2*I2[1];

Re = 0.2*Re_raw + 0.8*Re_raw[1];
Im = 0.2*Im_raw + 0.8*Im_raw[1];

# Compute the phase
if Re != 0 and Im != 0 then {
Period_raw = 2*double.PI / atan(Im/Re);
} else {
Period_raw = 0;
}

if Period_raw > 1.5*Period_raw[1] then {
Period_cap = 1.5*Period_raw[1];
} else if Period_raw < 0.67 * Period_raw[1] {
Period_cap = 0.67 * Period_raw[1];
} else {
Period_cap = Period_raw;
}

if Period_cap < 6 then {
Period_lim = 6;
} else if Period_cap > 50 then {
Period_lim = 50;
} else {
Period_lim = Period_cap;
}

Period = 0.2*Period_lim + 0.8*Period_lim[1];
SmoothPeriod = 0.33*Period + 0.67*SmoothPeriod[1];

if I1 != 0 then {
Phase = ATan(Q1 / I1);
} else if Q1 > 0 then { # Quadrant 1:
Phase = Double.Pi/2;
} else if Q1 < 0 then { # Quadrant 4:
Phase = -Double.Pi/2;
} else { # Both numerator and denominator are 0.
Phase = 0;
}

DeltaPhase_raw = Phase[1] - Phase;
If DeltaPhase_raw < 1 then {
DeltaPhase = 1;
} else {
DeltaPhase = DeltaPhase_raw;
}

alpha_raw = FastLimit / DeltaPhase;
If alpha_raw < SlowLimit then {
alpha = SlowLimit;
} else {
alpha = alpha_raw;
}
vmama = alpha*Price + (1 - alpha)*vmama[1];
vfama = 0.5*alpha*vmama + (1 - 0.5*alpha)*vfama[1];
}

plot MAMA = vmama;
plot FAMA = vfama;
}

declare upper;
input price = hl2;
input FastLimit = 0.5;
input SlowLimit = 0.05;

plot MAMA = Ehler_MAMA(price, FastLimit, SlowLimit).MAMA;
plot FAMA = Ehler_MAMA(price, FastLimit, SlowLimit).FAMA;

plot Crossing = crosses((MAMA < FAMA), yes);
Crossing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

plot Crossing1 = crosses((MAMA > FAMA), yes);
Crossing1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

AddChartLabel(yes, concat("MAMA: ", concat("",
If MAMA > FAMA then "Bull" else "Bear")),

If MAMA > FAMA then color.green else color.red);

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
REcommedations for programming help
Sierra Chart
What broker to use for trading palladium futures
Commodities
MC PL editor upgrade
MultiCharts
ZombieSqueeze
Platforms and Indicators
 
  #2 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,463 since Jun 2009
Thanks Given: 33,236
Thanks Received: 101,658

Tip

Please wrap code in the [code]put code here[/code] tags. This will prevent bad forum formatting and also make it easier to read the thread.



Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #3 (permalink)
ebtrader
east brunswick
 
Posts: 3 since Dec 2010
Thanks Given: 0
Thanks Received: 3


I am getting a bit closer. I can calculate a profit here after hardwiring an entry price, but did not yet figure out how to pick up the entry price nor keep a running tally of P&L nor get it to automate long or short:

 
Code
# hint: <b>Ehler's Mesa Adaptive Moving Average</b> using Ray's clean version
# of the homodyne discriminator. 
#

# MIT License
# Copyright (c) <2010> <Radford Juang>
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
#

script WMA_Smooth {
    input price = hl2;
    plot smooth = (4 * price 
                 + 3 * price[1] 
                 + 2 * price[2]
                 +   price[3]) / 10;
}

script Phase_Accumulation {
# This is Ehler's Phase Accumulation code. It has a full cycle delay. 
# However, it computes the correction factor to a very high degree.
#
    input price = hl2;

    rec Smooth;  
    rec Detrender;
    rec Period;
    rec Q1;
    rec I1; 
    rec I1p;
    rec Q1p;
    rec Phase1;
    rec Phase;
    rec DeltaPhase;
    rec DeltaPhase1;
    rec InstPeriod1;
    rec InstPeriod;
    def CorrectionFactor;
        
    if barNumber() <= 5
    then {
        Period = 0;
        Smooth = 0;
        Detrender = 0;
        CorrectionFactor = 0;
        Q1 = 0;
        I1 = 0;
        Q1p = 0;
        I1p = 0;
        Phase = 0;
        Phase1 = 0;
        DeltaPhase1 = 0;
        DeltaPhase = 0;
        InstPeriod = 0;
        InstPeriod1 = 0;
    } else {
        CorrectionFactor = 0.075 * Period[1] + 0.54;
    
        # Smooth and detrend my smoothed signal:
        Smooth = WMA_Smooth(Price);
        Detrender = ( 0.0962 * Smooth 
                        + 0.5769 * Smooth[2]
                        - 0.5769 * Smooth[4]
                        - 0.0962 * Smooth[6] ) * CorrectionFactor;

        # Compute Quadrature and Phase of Detrended signal:
        Q1p =        ( 0.0962 * Detrender 
                        + 0.5769 * Detrender[2]
                        - 0.5769 * Detrender[4]
                        - 0.0962 * Detrender[6] ) * CorrectionFactor;
        I1p = Detrender[3];

        # Smooth out Quadrature and Phase:
        I1 = 0.15 * I1p + 0.85 * I1p[1];
        Q1 = 0.15 * Q1p + 0.85 * Q1p[1];
        
        # Determine Phase
        if I1 != 0 then {
            # Normally, ATAN gives results from -pi/2 to pi/2. 
            # We need to map this to circular coordinates 0 to 2pi
            
            if Q1 >= 0 and I1 > 0 then { # Quarant 1
                Phase1 = ATan(absValue(Q1/I1));
            } else if Q1 >= 0 and I1 < 0 then { # Quadrant 2
                Phase1 = Double.PI - ATan(absValue(Q1/I1));
            } else if Q1 < 0 and I1 < 0 then { # Quadrant 3
                Phase1 = Double.PI + ATan(absValue(Q1/I1));
            } else { # Quadrant 4
                Phase1 = 2*Double.PI - ATan(absValue(Q1/I1));
            }
        } else if Q1 > 0 then {  # I1 == 0, Q1 is positive
            Phase1 = Double.PI/2;
        } else if Q1 < 0 then {  # I1 == 0, Q1 is negative
            Phase1 = 3*Double.PI/2;
        } else { # I1 and Q1 == 0
            Phase1 = 0;
        }

        # Convert phase to degrees
        Phase = Phase1 * 180 / Double.PI;

        if Phase[1] < 90 and Phase > 270 then { 
            # This occurs when there is a big jump from 360-0
            DeltaPhase1 = 360 + Phase[1] - Phase;
        } else {
            DeltaPhase1 = Phase[1] - Phase;
        }

        # Limit our delta phases between 7 and 60            
        if DeltaPhase1 < 7
        then {
            DeltaPhase = 7;
        } else if DeltaPhase1 > 60 then {
            DeltaPhase = 60;
        } else {
            DeltaPhase = DeltaPhase1;
        }

        # Determine Instantaneous period:            
        InstPeriod1 = 
            -1*(fold i=0 to 40 with v=0 do 
                if v < 0 then
                    v
                else if v > 360 then 
                    -i
                else 
                    v + getValue(DeltaPhase, i, 41)
                );

        if InstPeriod1 <= 0 then {
            InstPeriod = InstPeriod[1];
        } else {
            InstPeriod = InstPeriod1;
        }
    
        Period = 0.25*InstPeriod + 0.75*Period[1];
    }
    plot DC = period;
}

script Ehler_MAMA {
    input price = hl2;
    input FastLimit = 0.5;
    input SlowLimit = 0.05;


    rec Period;
    rec Period_raw;
    rec Period_cap;
    rec Period_lim;

    rec Smooth;  
    rec Detrender;
    rec I1; 
    rec Q1;
    rec jI;
    rec jQ;
    rec I2;
    rec Q2;
    rec I2_raw;
    rec Q2_raw;

    rec Phase;
    rec DeltaPhase;
    rec DeltaPhase_raw;
    rec alpha;
    rec alpha_raw;

    rec Re;
    rec Im;
    rec Re_raw;
    rec Im_raw;

    rec SmoothPeriod;
    rec vmama;
    rec vfama;

    def CorrectionFactor = Phase_Accumulation(price).CorrectionFactor;
          
    if barNumber() <= 5
    then {
        Smooth = 0;
        Detrender = 0;

        Period = 0;
        Period_raw = 0;
        Period_cap = 0;
        Period_lim = 0;
        I1 = 0;
        Q1 = 0;
        I2 = 0;
        Q2 = 0;
        jI = 0;
        jQ = 0;
        I2_raw = 0;
        Q2_raw = 0;
        Re = 0;
        Im = 0;
        Re_raw = 0;
        Im_raw = 0;
        SmoothPeriod = 0;
        Phase = 0;
        DeltaPhase = 0;
        DeltaPhase_raw = 0;
        alpha = 0;
        alpha_raw = 0;
        vmama = 0;
        vfama = 0;
    } else {    
        # Smooth and detrend my smoothed signal:
        Smooth = WMA_Smooth(Price);
        Detrender = ( 0.0962 * Smooth 
                    + 0.5769 * Smooth[2]
                    - 0.5769 * Smooth[4]
                    - 0.0962 * Smooth[6] ) * CorrectionFactor;

        Q1 = ( 0.0962 * Detrender 
                    + 0.5769 * Detrender[2]
                    - 0.5769 * Detrender[4]
                    - 0.0962 * Detrender[6] ) * CorrectionFactor;
        I1 = Detrender[3];
        
        jI = ( 0.0962 * I1 
                    + 0.5769 * I1[2]
                    - 0.5769 * I1[4]
                    - 0.0962 * I1[6] ) * CorrectionFactor;

        jQ = ( 0.0962 * Q1 
                    + 0.5769 * Q1[2]
                    - 0.5769 * Q1[4]
                    - 0.0962 * Q1[6] ) * CorrectionFactor;
        
        # This is the complex conjugate
        I2_raw = I1 - jQ;
        Q2_raw = Q1 + jI;
        
        I2 = 0.2*I2_raw + 0.8*I2_raw[1];
        Q2 = 0.2*Q2_raw + 0.8*Q2_raw[1];

        Re_raw = I2*I2[1] + Q2*Q2[1]; 
        Im_raw = I2*Q2[1] - Q2*I2[1]; 

        Re = 0.2*Re_raw + 0.8*Re_raw[1];
        Im = 0.2*Im_raw + 0.8*Im_raw[1];

        # Compute the phase
        if Re != 0 and Im != 0 then {
            Period_raw = 2*double.PI / atan(Im/Re);
        } else {
            Period_raw = 0;
        }

        if Period_raw > 1.5*Period_raw[1] then {
            Period_cap = 1.5*Period_raw[1];
        } else if Period_raw < 0.67 * Period_raw[1] {
            Period_cap = 0.67 * Period_raw[1];
        } else {
            Period_cap = Period_raw;
        }

        if Period_cap < 6 then { 
            Period_lim = 6;
        } else if Period_cap > 50 then {
            Period_lim = 50;
        } else {
            Period_lim = Period_cap;
        }
        
        Period = 0.2*Period_lim + 0.8*Period_lim[1];
        SmoothPeriod = 0.33*Period + 0.67*SmoothPeriod[1];

        if I1 != 0 then {  
            Phase = ATan(Q1 / I1);
        } else if Q1 > 0 then {  # Quadrant 1:
            Phase = Double.Pi/2;
        } else if Q1 < 0 then {  # Quadrant 4:
            Phase = -Double.Pi/2;
        } else { # Both numerator and denominator are 0. 
            Phase = 0;
        }
        
        DeltaPhase_raw = Phase[1] - Phase;
        If DeltaPhase_raw < 1 then {
          DeltaPhase = 1;
        } else {
          DeltaPhase = DeltaPhase_raw;
        }

        alpha_raw = FastLimit / DeltaPhase;
        If alpha_raw < SlowLimit then {
            alpha = SlowLimit;
        } else {
            alpha = alpha_raw;
        }
       vmama = alpha*Price + (1 - alpha)*vmama[1];
       vfama = 0.5*alpha*vmama + (1 - 0.5*alpha)*vfama[1];
    }

    plot MAMA = vmama;
    plot FAMA = vfama;
}

declare upper;
input price = hl2;
input FastLimit = 0.5;
input SlowLimit = 0.05;

plot MAMA = Ehler_MAMA(price, FastLimit, SlowLimit).MAMA;
plot FAMA = Ehler_MAMA(price, FastLimit, SlowLimit).FAMA;

plot Crossing = crosses((MAMA < FAMA), yes);
Crossing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

plot Crossing1 = crosses((MAMA > FAMA), yes);
Crossing1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

AddChartLabel(yes, concat("MAMA: ",  concat("",  
If MAMA > FAMA then "Bull" else "Bear")), 

If MAMA > FAMA then color.green else  color.red);

# Entry price calculation and storage
#rec entry_price = if crosses((MAMA < FAMA), yes) 
#then close 
#else entry_price[1];
input StartPrice = 1200;

# Exit price calculation and storage
rec exit_price = if crosses((MAMA > FAMA), yes) 
then close 
else exit_price[1];
def curPrice = exit_price;

#################################
# Study: VicEquity

# Date: Dec 1 2010
# Purpose: to display current P/L equity position on chart window.
#################################

# User Inputs:
input TransactionType = {default Long, "Short"}; # Define if we are going long or short
input ContractSize = 1; # number of contracts bought or sold
input Equity = {default "/ES", "/6A", "/TF", "/YM", "/NQ", "/6E", "/GC", "/CL"}; # drop down list of several symbols

# different futures have different multipliers... let's hard code it for one time...great if it can be pulled from some library/repository
def FuturesMultiplier;
def tickSize;

switch (Equity) {
case "/ES": # S & P E-mini
FuturesMultiplier = 12.5;
tickSize = .25;

case "/6A": # Aussie
FuturesMultiplier = 125000;
tickSize = 1; # I have no idea, someone else can look this up
default:
FuturesMultiplier = 1;
tickSize = 1;
}

def ProfitLoss;
switch (TransactionType) {
case "Long":
ProfitLoss = (CurPrice - StartPrice)/tickSize * ContractSize * FuturesMultiplier;
case "Short":
ProfitLoss = (StartPrice - CurPrice)/tickSize * ContractSize * FuturesMultiplier;

}

# Label on top left corner
# paste a label on upper chart showing the P/L for the contract..
AddChartLabel(yes,
concat(getSymbolPart(), concat(TransactionType, concat(" : $", ProfitLoss))),
if ProfitLoss >= 0 then color.green else color.red );

Reply With Quote
Thanked by:




Last Updated on December 11, 2010


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts