DCA using MACD and EMA
Budget: ₹12,500 – ₹37,500 INR
Develop a DCA pine script for long trading. Features include
Place orders
Order 1 (L1) determined by EMA fast being above EMA slow. These will be the EMAs in the MACD. When L1 is executed the script will take the following actions:
Record purchase price LP1
Calculate take profit price (TPP)
Calculate Order 2 maximum price (LP2_max). This is a user defined input % below LP1
Order 2 (L2) is executed when MACD crosses up AND the current price is less than LP2_max
When L2 is executed the script will take the following actions:
Record purchase price LP2
Calculate REVISED take profit price (TPP). This replaces previous TPP.
Calculate Order 3 maximum price (LP3_max). This is a user defined input % below LP2
Order 3 (L3) is executed when MACD crosses up AND the current price is less than LP3_max
When L3 is executed the script will take the following actions:
Record purchase price LP3
Calculate REVISED take profit price (TPP). This replaces the previous TPP.
Calculate Order 4 maximum price (LP4_max). This is a user defined input % below LP3
Order 4 (L4) is executed when MACD crosses up AND the current price is less than LP4_max
When L4 is executed the script will take the following actions:
Record purchase price LP4
Calculate REVISED take profit price (TPP). This replaces previous TPP.
Calculate Order 5 maximum price (LP5_max). This is a user defined input % below LP4
Repeat to Order 7
Alerts for Place orders.
Alerts to be coded to provide a message to 3Commas when the conditions are met for each order. The amount of the order will be a user input variable.
Take profit
The take profit will be based on a user defined % (user input defal value = 1.5%, from 0.5 to 5.0 % in steps of 0.1%)
The take profit price (TPP)will be based on a weighted average purchase price. So the script must calculate the revised weighted average purchase price after each order and then calculate the revised TPP. This will replace the previous TPP.
When the TPP is reached an alert will be triggered to close the deal. The script then resets to execute again if the conditions are met
Plotting
Plot L1, L2 L3 etc as they execute and the updated TPP.
Place orders
Order 1 (L1) determined by EMA fast being above EMA slow. These will be the EMAs in the MACD. When L1 is executed the script will take the following actions:
Record purchase price LP1
Calculate take profit price (TPP)
Calculate Order 2 maximum price (LP2_max). This is a user defined input % below LP1
Order 2 (L2) is executed when MACD crosses up AND the current price is less than LP2_max
When L2 is executed the script will take the following actions:
Record purchase price LP2
Calculate REVISED take profit price (TPP). This replaces previous TPP.
Calculate Order 3 maximum price (LP3_max). This is a user defined input % below LP2
Order 3 (L3) is executed when MACD crosses up AND the current price is less than LP3_max
When L3 is executed the script will take the following actions:
Record purchase price LP3
Calculate REVISED take profit price (TPP). This replaces the previous TPP.
Calculate Order 4 maximum price (LP4_max). This is a user defined input % below LP3
Order 4 (L4) is executed when MACD crosses up AND the current price is less than LP4_max
When L4 is executed the script will take the following actions:
Record purchase price LP4
Calculate REVISED take profit price (TPP). This replaces previous TPP.
Calculate Order 5 maximum price (LP5_max). This is a user defined input % below LP4
Repeat to Order 7
Alerts for Place orders.
Alerts to be coded to provide a message to 3Commas when the conditions are met for each order. The amount of the order will be a user input variable.
Take profit
The take profit will be based on a user defined % (user input defal value = 1.5%, from 0.5 to 5.0 % in steps of 0.1%)
The take profit price (TPP)will be based on a weighted average purchase price. So the script must calculate the revised weighted average purchase price after each order and then calculate the revised TPP. This will replace the previous TPP.
When the TPP is reached an alert will be triggered to close the deal. The script then resets to execute again if the conditions are met
Plotting
Plot L1, L2 L3 etc as they execute and the updated TPP.